angularjs - Why is controller created twice? -
consider following angularjs app:
- http://jsfiddle.net/pathes/qpl3r/ - application based on tutorial angularjs.org homepage,
- http://jsfiddle.net/pathes/cuaev/ - jasmine tests.
method addpane() pushes pane controller's pane list, panecount() returns length. after creating 3 panes, accessing method panecount() binding {{panecount()}} , directly in test: scope.panecount() returns 0.
it appears angularjs creates 2 instances of controller - 1 accessible controller methods, scope's. know why there's need of creating 2 instances? there way access same properties both controller , scope methods?
the problem controller definition of yours! defined scope twice. once in controller , once in directive definition of tabs directive. directive definition overrides scope of controller , therefore count not correct.
- http://jsfiddle.net/pathes/z2ewt/ - i've forked fiddle update
// scope: {}, not necessary because defined in controller ctrl
hope helps :)
Comments
Post a Comment