Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to build web app that dynamically load interfaces, using angularJS.

I found that it was possible to bootstrap some portions of my code after the initial bootstrap of Angular (HTML template + Controller). My problem is that, doing so, the 2-way data-binding doesn't work. See for yourself:

http://plnkr.co/edit/MtAWP6

Any idea? Am I seeking for something to do the wrong way?

Thanks!

share|improve this question
up vote 1 down vote accepted

Your problem isn't a bootstraping one (although you really shouldn't be using bootstrap to instantiate a controller, but rather $compile, imo - see this answer). It is a scope problem. You define a "mymodel" model in your controller, but then define it again in your form, for which angular automatically creates it's own scope. While the form's scope inherits from the parent scope, and thus seems to be "binding" the model, the inverse doesn't happen.

You need to either establish a binding between both scopes (or $watch the form's variable, or define the for in the surronding controller), or just assign the controller you want to the form, directly.

See your problem exposed here (see that while your $timeout changes both models, manually setting the model only changes one)

See it resolved here (by basically assigning your controller to the generated form, rather than to a enclosing div of said form)

share|improve this answer
    
Well, thanks! Now I know why it didn't worked. – Alain Duchesneau Dec 9 '12 at 12:36
    
I did put that controller assignment in my script in order to eventually change dynamically what controller should be used... I guess that I"ll have to keep my things more in pair (controller <-> view) than I first tought. Maybe it's a good thing after all.. – Alain Duchesneau Dec 9 '12 at 12:44

I think maybe you should take another look at routing/ deep linking. You should be able to specify both a template url and a controller.

Check out this video

And the api docs

share|improve this answer
    
I can't use routing in my app. What I do is building a CMS which is loaded on top of oters websites. So I can't mix 2 URL routings… – Alain Duchesneau Dec 9 '12 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.