Kendo-ui angular 编辑器指令

Kendo-ui angular directive on editor

我正在尝试将 angular 指令附加到 `

 {
   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 页面之外,它工作得很好,但不是在这里。我还以为是版本问题,升级到这个月的最新版本也没用

有什么线索吗?

-谢谢,

You need to compile your html before appending it (using $compile service).

所以在你的 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