Can someone please help!
I am very much confused about this and $scope in angularJS.
Suppose here is my html:
<div ng-controller = "myController">
<input type = "text" data-ng-model = "testing">
</div>
My controller
When I write:
$scope.testing = "Rest"; // this works fine
but:
this.testing = "Rest" // this does not work
This works when I give alias to controller and use it
<div ng-controller = "myController as ctrl">
<input type = "text" data-ng-model = "ctrl.testing">
</div>
Also here is my complete code where I am totally confused:
<div ng-controller = "myController as ctrl">
<input type = "text" data-ng-model = "ctrl.testing">
</div>
<ng-form>
{{testing}}
<input type="button" ng-click="test()">
</ng-form>
Now in my controller
$scope.test = function(){
this.testing = "Work" // This thing changes only the form variable not the actual why ??
}
And also ng-form does not create its own scope.. then
Also if in controller if I defined my test function
this.test = function() {
}// This is not called why??
Can someone please explain what's going on here. I am very much confused about this and scope.
Also $apply
- does it also check my variables?
Also this is not a duplicate i have many aspects which i am very much confused.