see the code
<div ng-app="myApp" ng-controller="ctrlCarLists as cars">
<button ng-click="cars.showCars()">
Cars
</button>
<button ng-click="alert(cars.data)">
Test
</button>
</div>
var app = angular.module('myApp', []);
app.controller("ctrlCarLists", function () {
this.data = 'hello';
this.showCars = function () {
alert("Ford, Toyata, Mercedes");
};
});
i am new in angular so not being able to understand when people do not like to have $scope in controller. so please tell me or show me few scenario with example when people create controller without scope.
what is the meaning of this ctrlCarLists as cars ?
many people may say by this code ctrlCarLists as cars
we are creating instance of controller to access property of controller but when we use $scope then controller instance is created too.
please help me to understand..
thanks