When using the 'controller as' approach instead of $scope, I am encountering issues with method calling from HTML. My question is, how many ways are there to declare and call functions using this approach?
First: (For executing something initially)
var vm = this;
vm.dataOne = [];
function funcOne() {
myService.serviceFunc()
.then(function(response) {
vm.dataOne = response.data;
});
};
function activate() {
funcOne();
}
activate();
Second: (For initializing a variable based on a function's returned value)
vm.dataTwo = function() {
doSomething();
}
- Are there any other ways?
How can we define a function in the controller that will be called from HTML, like
ng-click="ctrl.dataTwo()";