Reputation: 622
ng-change does not trigger my function anyhow, here is the view;
<div ng-controller="widgets.lunchMenu as vm">
<label class="btn btn-transparent grey-salsa btn-circle btn-sm active">
<input type="radio" name="options" class="toggle" id="option1" ng-model="vm.takeCount" ng-value="0" ng-change="vm.getLunchMenus()">@L("Today")
</label>
<label class="btn btn-transparent grey-salsa btn-circle btn-sm">
<input type="radio" name="options" class="toggle" id="option2" ng-model="vm.takeCount" ng-value="7" ng-change="vm.getLunchMenus()">@L("Week")
</label>
<label class="btn btn-transparent grey-salsa btn-circle btn-sm">
<input type="radio" name="options" class="toggle" id="option3" ng-model="vm.takeCount" ng-value="30" ng-change="vm.getLunchMenus()">@L("Month")
</label>
</div>
here is the controller :
(function () {
appModule.controller('widgets.lunchMenu', [
'$scope', 'abp.services.app.lunch',
function ($scope, appService) {
var vm = this;
var today = new Date();
var month = today.getMonth();
vm.getLunchMenus = function () {
appService.getLunchMenus({ month: month + 1, takeCount: vm.takeCount }).success(function (data) {
vm.menus = data.items;
});;
};
vm.getLunchMenus();
}
]);
})();
any suggestion ? thanks for helping.
Upvotes: 0
Views: 120
Reputation: 571
In order for the ng-change
directive to be able to see the vm.getLunchMenus
function, it has to be on the $scope
. So you'd need to do something along the lines of:
$scope.vm = this;
$scope.vm = function() { ... }
Then in your markup, you could do what you're doing with
ng-change="vm.getLunchMenus()"
Or you could just do something as simple as
$scope.getLunchMenus = function() { ... }
Then in the markup:
ng-change="getLunchmenus()"
Do completely remove the need for the vm
variable, since this
doesn't really mean anything to the directives (ng-change
, etc.) in the markup.
Upvotes: 1