2015-02-05 105 views
1

我已经注意到其他kendo-ui控件的这个问题,但我会特别询问关于kendo-notification。我的HTML有:kendo-ui通知范围变量未在角度控制器中设置

<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://localhost:57624/app/layout/shell.controller.js:41:24) 在新shell不能读取的不确定 财产“秀”(http://localhost:57624/app/layout/shell.controller.js:32:9

我敢肯定,我失去了一些东西有关对象的状态Angular,但我错过了什么,我不能在控制器的加载阶段显示此通知?

回答

1

当您在控制器功能中调用激活时,Kendo UI小部件尚未创建。一种解决方法是使用全球事件剑道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(); 
     }); 
    } 
); 

demo

+0

伟大的工作,谢谢! – 2015-02-09 14:49:50