剑道的UI通知范围的变量在角控制器未设定 [英] kendo-ui notification scope variable not set in Angular controller

查看:181
本文介绍了剑道的UI通知范围的变量在角控制器未设定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到与其他剑道的UI控件这个问题,但我会约剑道通知特别要求。我的HTML有:

I've noticed this issue with other kendo-ui controls, but I'll ask specifically about kendo-notification. My html has:

<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');
    }

}
})();

我的问题:如果我按一下按钮,我得到的通知。但是,上载,我得到:
类型错误:无法读取属性'秀'的未定义
    在激活(的http://本地主机:57624 /应用/布局/壳。 controller.js:41:24
    在新的外壳(的http://本地主机:57624 /应用/布局/壳.controller.js:32:9

我敢肯定,我失去了一些东西在左右角对象的状态,但我缺少什么,在控制器的负荷相?

I'm sure I'm missing something about the object state in Angular, but what am I missing that I cannot show this notification during the load phase of the controller?

推荐答案

当你调用控制器功能激活,剑道UI部件还没有被创建。一种解决方法是使用全球事件剑道UI具有此方案中的一个(的 kendoRendered ):

When you're calling activate in the controller function, the Kendo UI widget has not been created yet. One solution to this is to use one of the global events Kendo UI has for this scenario (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();
        });
    }
);   

演示

这篇关于剑道的UI通知范围的变量在角控制器未设定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆