Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
rohitkandhal opened this issue Apr 12, 2015 · 3 comments
Open

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

rohitkandhal opened this issue Apr 12, 2015 · 3 comments

Comments

@rohitkandhal
Copy link

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.

@rohitkandhal rohitkandhal changed the title Don't bind to the $scope directly ngModel: Don't bind to the $scope directly Apr 12, 2015
@rohitkandhal rohitkandhal reopened this Apr 12, 2015
@brockallen
Copy link

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

@spmorgan
Copy link
Member

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
Copy link
Author

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?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants