LearningLine / essential-angularjs-demos

Creative Commons Zero v1.0 Universal
1 stars 1 forks source link

ngModel: Don't bind to the $scope directly #1

Open rohitkandhal opened 9 years ago

rohitkandhal commented 9 years ago

One slide states Always bind to a property of a child object. I assume it's applicable only for objects defined on scope, not arrays or properties.

brockallen commented 9 years ago

It's because of this issue: https://egghead.io/lessons/angularjs-the-dot

spmorgan commented 9 years ago

It's because of variable "hiding" that happens when setting a variable on child scopes.

Sent from my iPhone

On Apr 12, 2015, at 4:13 PM, Rohit Kandhal notifications@github.com wrote:

One slide states Always bind to a property of a child object. I assume it's applicable only for objects defined on scope, not arrays or properties.

— Reply to this email directly or view it on GitHub.

rohitkandhal commented 9 years ago

Thank you @brockallen, @spmorgan. Egghead tutorial is interesting. Also noticed, if I define data.message property in my controller then it is not shared.

If I define data.message object/property on scope like following, then it's not shared.

function FirstCtrl($scope) { $scope.data = { "message" : "test 1" }; }

function SecondCtrl($scope) { $scope.data = { "message" : "test 2" }; }

I believe this difference is pointed out at the end of video. I am wondering how I'll access the model in controller, if not using $scope. How should I read data.message in controller?