Nikita, An single controller instance is created per directive (an directive can have more then one controller), it has noting to do with transclude. The `$scope` argument in your controller and `scope` argument in your `link` method are same as you have your controller outside your template, if its was inside also it depends on the value set for `scope` property while declaring the directive. You can check to see if the `scope` & `$scope` are same by `$id` property if the they match ($scope.$id === scope.$id) you have the same scope.
Cheers, Kamal On Monday, 21 April 2014 23:28:20 UTC+5:30, Nikita Tovstoles wrote: > > So, fwiw I think the answers are: > > 1. there is only one NgModelController instance, and it is actually at > $scope.mainForm.fooForm.myInput ($scope is the one in MainCtrl) > 2. '$scope' inside the above NgModelController is NOT the one from > MainCtrl - rather it is the transcluded scope (created via prototypal > inheritance from MainCtrl.$scope) > > #1 makes sense; not sure I fully understand why $scope in #2 is NOT > MainCtrl.$scope. Could someone please explain? > > thanks, > -nikita > > On Sunday, April 20, 2014 9:47:44 AM UTC-7, Nikita Tovstoles wrote: >> >> Say we have a transclude directive <foo> (with iso scope) wrapping an >> input: >> >> <div ng-controller="MainCtrl"> >> <form name="mainForm"> >> <foo><input ng-model="myInput" name="myInput" type="text"></foo> >> </form> >> </div> >> >> where <foo> has the following template: >> >> <div ng-form="fooForm"> >> <div ng-transclude></div> >> <button ng-click="saveChanges()">ok</button> >> <button ng-click="cancelChanges()">cancel</button> >> </div> >> >> NgModelController takes a scope as constructor param. Does that mean that >> there will/can be multiple instances of NgModelController associated with >> transcluded <input>: >> >> 1. one at $scope.mainForm.myInput (using $scope from MainCtrl) >> 1. mainForm will also be accessible to transcluded scope (via >> prototypal inheritance) >> 2. another at scope.fooForm.myInput (using isolate scope from <foo>) >> >> >> ...and if so, can those two ctrls at times have unequal $viewValue and >> $modelValue values - since the latter is derived from NgModelController's >> scope? >> >> -nikita >> >> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
