Why does this not work: http://codepen.io/anon/pen/YPbybY
If I change ng-model=“newNumber” to ng-model="$parent.newNumber" in the input field it works:
But why does it need to be $parent?
Why does this not work: http://codepen.io/anon/pen/YPbybY
If I change ng-model=“newNumber” to ng-model="$parent.newNumber" in the input field it works:
But why does it need to be $parent?
The way that angular will bind variables is by using a parent object. SO, because the variable is directly assigned to scope, you have to basically ask it to get the variable from scope.
Best practice is to have a separate object in the scope. So instead of doing $scope.newNumber do something like $scope.inputs = {
newNumber : 0
}
Then in your template file, instead of referencing just “newNumber” have it use “inputs.newNumber”.
Let me know how that works out for you
PS this keeps your code a lot cleaner as well especially when you have large forms.
@nnnnnorthhhhh - what about a function as a value in `$scope.inputs = { … } ?
How would that be added to the scope and then referenced in the HTML?