2015-02-05 53 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