剑道UI和角度 - 在$范围不小部件 [英] Kendo UI and angular - no widget in $scope

查看:194
本文介绍了剑道UI和角度 - 在$范围不小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是剑道UI版本2014.2.716与AngularJS版本1.2.27,我用一条指令做出网格

I'm using Kendo UI version 2014.2.716 with AngularJS version 1.2.27, and I made a grid using a directive

<div ng-controller="MyController as ctrl">
    <div id="myGrid" kendo-grid k-options="{some options}"></div>
    <button ng-click="ctrl.doSomething()"></div>
</div>

我看了,如果你给一个名字到电网(是这样的:剑道格=myGridOnScope),您可以访问小部件控制器范围是这样的:

I read that if you give a name to the grid (like this: kendo-grid="myGridOnScope"), you can access the widget in the controller scope in this way:

myModule.controller('MyController', function($scope) {
   this.doSomething = function() {
       console.log($scope.myGridOnScope);
   }
}

本的console.log应登录一个widget对象,但对我来说这是不确定的。我究竟做错了什么?感谢您的帮助。

The console.log should log a widget object, but in my case it's undefined. What am I doing wrong? Thanks for the help

推荐答案

我已经找到了自己的问题,所以我要发布一个答案,如果有人有同样的问题。如果您使用的AngularJS语法controllerAs,你不能只是写widget的名字 - 你必须与你的控制器别名preFIX它

I have found out the problem myself, so I'm going to post an answer if someone has the same problem. If you use the controllerAs syntax in AngularJS, you can't just write the name of the widget - you have to prefix it with your controller alias.

在这个例子看看:

<div ng-controller="MyController as ctrl">
    <div kendo-grid="myGridName"></div>
</div>

这不会给你的 $范围网格对象 - 为您需要添加 CTRL preFIX:

This will not give you the grid object on the $scope - for that you need to add the ctrl prefix:

<div ng-controller="MyController as ctrl">
    <div kendo-grid="ctrl.myGridName"></div>
</div>

现在你有机会获得小部件在您的控制器是这样的:

Now you have access to the widget in your controller like this:

angular.module('MyModule',['kendo.directives'])
    .controller('MyController', function($scope){
        // this gives you the widget object
        console.log(this.myGridName);

        // however, this doesn't work
        console.log($scope.myGridName);
});

我希望我帮助别人这个职位。
欢呼声中,

I hope I helped someone with this post. Cheers,

这篇关于剑道UI和角度 - 在$范围不小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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