Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 指令不';在元素替换为jQuery之后转换属性_Angularjs_Kendo Ui_Kendo Dropdown - Fatal编程技术网

Angularjs 指令不';在元素替换为jQuery之后转换属性

Angularjs 指令不';在元素替换为jQuery之后转换属性,angularjs,kendo-ui,kendo-dropdown,Angularjs,Kendo Ui,Kendo Dropdown,我尝试执行指令,其中包括动态模板,但有一个问题-编译完所有属性后,包括ng模型,都无法转换为新元素,ng模型也无法工作。 我错在哪里 元素代码: <input type-test="kendo"> getTemplateUrl()根据输入参数(attrs.typeTest)返回模板的url 模板类型测试=“剑道”: 列表的定义类似于[{Id:1,名称:'First'},{Id:2,名称:'Second'}]。不应替换指令链接函数中的元素。链接函数应该只设置事件侦听器以使指令工作

我尝试执行指令,其中包括动态模板,但有一个问题-编译完所有属性后,包括ng模型,都无法转换为新元素,ng模型也无法工作。 我错在哪里

元素代码:

<input type-test="kendo">
getTemplateUrl()根据输入参数(attrs.typeTest)返回模板的url

模板类型测试=“剑道”:



列表的定义类似于[{Id:1,名称:'First'},{Id:2,名称:'Second'}]。

不应替换指令链接函数中的元素。链接函数应该只设置事件侦听器以使指令工作。将逻辑放在编译函数而不是链接函数中。这里有一篇关于它的很好的文章:

我找到了一个解决方案:

    App.directive('dynamicType', ['$compile',
        function ($compile) {
            return {
                compile: function compile(tElement, tAttrs, transclude) {
              return {
                pre: function preLink(scope, iElement, iAttrs, controller) { 
                            var tpl = "<input type-test='"+iAttrs.dynamicType+"'>";
                            iElement.html(tpl);
                            $compile(iElement.contents())(scope);
                 },
                post: function postLink(scope, iElement, iAttrs, controller) {}
              }
                }
            }
        }
    ]);
App.directive('dynamicType',['$compile',
函数($compile){
返回{
编译:函数编译(远程通讯、tAttrs、转置){
返回{
前置:功能预链接(范围、IELENT、iAttrs、控制器){
var tpl=“”;
html(tpl),;
$compile(iElement.contents())(范围);
},
post:函数postLink(作用域、IELENT、iAttrs、控制器){}
}
}
}
}
]);
该指令编译新元素,然后将其链接,然后将控制返回到typeTest指令-以编译和链接其他元素

要素:

<input dynamic-type="kendo">

无论如何,这并不能解决问题-我不能用ng模型绑定新元素。
    App.directive('dynamicType', ['$compile',
        function ($compile) {
            return {
                compile: function compile(tElement, tAttrs, transclude) {
              return {
                pre: function preLink(scope, iElement, iAttrs, controller) { 
                            var tpl = "<input type-test='"+iAttrs.dynamicType+"'>";
                            iElement.html(tpl);
                            $compile(iElement.contents())(scope);
                 },
                post: function postLink(scope, iElement, iAttrs, controller) {}
              }
                }
            }
        }
    ]);
<input dynamic-type="kendo">