【问题标题】:Kendo-ui angular directive on editor编辑器上的 Kendo-ui 角度指令
【发布时间】:2016-09-17 19:44:09
【问题描述】:

我正在尝试将一个角度指令附加到`

 {
   field:"stateID", 
   hidden: true,
   title: "State",
   editor: function (container, options) {
   var _statesDirective = $('<div><my-states></my-states></div>');
  _statesDirective.appendTo(container);
}`

我的指令如下所示:

appRoot.directive('myStates', function () {
return {
    restrict: 'EA',
    templateUrl: 'directivesHTML/ddStates.html',
    scope:false,
    controller: function ($scope)
    {
        var    dsStates = new kendo.data.DataSource({
                autoBind: false,
                page: 1,
                transport: {

                    read: {
                        url: "api/util/getStates",
                        dataType: "json"
                    }
                },

                schema: {
                    model: {
                        id: "stateID",
                        fields: {
                            stateID: { type: 'string' },
                            name: { type: "string" }
                        }
                    }
                }

            });


        dsStates.read().then(function () {

                $('#ddStates')
                .kendoDropDownList({
                    dataTextField: "name",
                    dataValueField: "stateID",
                    dataSource: dsStates,
                    optionLabel: '--',
                    change: function (e) {
                            }

                });
        });

    }
};

});

由于某些奇怪的原因,它不起作用,如果我将指令放在其他地方,任何外部 html 页面,它都可以正常工作,但不是从这里开始。还以为是这个版本,升级到本月最新的,没用。

有什么线索吗?

-谢谢,

【问题讨论】:

  • 我已经有一段时间没有这样做了,尝试用angular.element 代替$ 开始
  • 谢谢,试过了,没用,但是谢谢你的提示。

标签: angularjs kendo-ui directive


【解决方案1】:

您需要在附加之前编译您的 html(使用 $compile 服务)。

所以在你的editor: function

// Specify what it is we'll be compiling.
var to_compile = '<div><my-states></my-states></div>';
// Compile the tag, retrieving the compiled output.
var _statesDirective = $compile(to_compile)($scope);
// Ensure the scope and been signalled to digest our data.
$scope.$digest();

// Append the compiled output to the page.
$compiled.appendTo(_statesDirective);

如需更多参考,Angular Docs for $compile

另外,how can we use $compile outside a directive in Angularjs

【讨论】:

  • 嗯,你知道什么? ....这是绝对正确的!非常感谢!
猜你喜欢
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多