1

我已经注意到其他 kendo-ui 控件的这个问题,但我会特别询问有关 kendo-notification 的问题。我的html有:

<span kendo-notification="vm.notifier"></span>
<button ng-click="vm.push()">Push it</button>

在我的控制器中,我有:

(function () {
'use strict';

angular
    .module('app.layout')
    .controller('Shell', Shell);

function Shell() {
    /*jshint validthis: true */
    var vm = this;

    vm.push = push;

    activate();

    function activate() {
        vm.notifier.show('Loaded', 'info');
    }

    function push() {
        vm.notifier.show('Pushed', 'info');
    }

}
})();

我的问题:如果我点击按钮,我会收到通知。但是,在加载时,我得到: TypeError: Cannot read property 'show' of undefined at activate ( http://localhost:57624/app/layout/shell.controller.js:41:24 ) at new Shell ( http:// /localhost:57624/app/layout/shell.controller.js:32:9 )

我确定我在 Angular 中遗漏了一些关于对象状态的信息,但是我错过了什么我无法在控制器的加载阶段显示此通知?

4

1 回答 1

1

当您在控制器函数中调用 activate 时,尚未创建 Kendo UI 小部件。对此的一种解决方案是使用 Kendo UI 用于此场景 ( kendoRendered) 的全局事件之一:

angular.module('app.layout', [ "kendo.directives" ])
    .controller('Shell', function ($scope) {       
        $scope.activate = function () {
            $scope.notifier.show('Loaded', 'info');
        };

        $scope.push = function () {
            $scope.notifier.show('Pushed', 'info');
        };

        $scope.$on("kendoRendered", function(event){
            $scope.activate();
        });
    }
);   

演示

于 2015-02-08T03:55:50.110 回答