Imagine having a NameController implemented in AngularJS. You can define variables like so:
this.name = 'Joe';
Alternatively, you could use:
$scope.name = 'Joe';
I have a preference for accessing all variables using object notation:
<form ng-controller="NameController as nameCtrl">
<input type="text" ng-model="nameCtrl.name">
</form>
This method only works when utilizing the 'this' notation in the controller. If using $scope
, I would need to call 'name' without the nameCtrl
prefix to make it function.
I acknowledge that I may be overlooking some essential basics here, but even after extensive research, I still find myself at an impasse. How can I maintain consistent object naming in my HTML code?