简体   繁体   English

ng-change不会触发

[英]ng-change does not trigger

ng-change does not trigger my function anyhow, here is the view; ng-change不会触发我的功能,这是视图;

            <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. 感谢您的帮助。

In order for the ng-change directive to be able to see the vm.getLunchMenus function, it has to be on the $scope . 为了使ng-change指令能够看到vm.getLunchMenus函数,它必须位于$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. 完全不需要vm变量,因为this实际上对标记中的指令( ng-change等)没有任何意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM