Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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 如何将Angle指令绑定到kendo ui模型_Angularjs_Kendo Ui - Fatal编程技术网

Angularjs 如何将Angle指令绑定到kendo ui模型

Angularjs 如何将Angle指令绑定到kendo ui模型,angularjs,kendo-ui,Angularjs,Kendo Ui,我已经搜索了很多,在网上找不到类似的问题和解决方案,但我已经把头撞在墙上太久了 我想把angular模型/对象传递给指令,这样当它返回一个新元素时,它就会绑定到旧的模型/对象。。。 当前它正在返回值 我已经尽力使代码尽可能简单明了 希望这有意义: 指令: (function () { angular.module('myMod').directive('myDir', ['$compile', function ($compile) { retur

我已经搜索了很多,在网上找不到类似的问题和解决方案,但我已经把头撞在墙上太久了

我想把angular模型/对象传递给指令,这样当它返回一个新元素时,它就会绑定到旧的模型/对象。。。 当前它正在返回值 我已经尽力使代码尽可能简单明了

希望这有意义:

指令:

(function () {
    angular.module('myMod').directive('myDir', ['$compile',
        function ($compile) {
            return {
                restrict: 'E',
                replace: true,
                scope: {
                    type: '@',
                    val: '@'
                },
                link: function (scope, element, attrs) {                
                    var newEl;                   
                    switch (scope.type) {
                        case "1":
                            newEl = '<input type="text" class="k-textbox" k-ng-model="{{val}}"  />';
                            break;
                        case "2":
                            newEl = '<input kendo-date-picker k-ng-model="{{val}}" />';
                            break;
                    }
                    element.replaceWith($compile(newEl)(scope));

                }
            };
        }
    ]);
})();
(函数(){
angular.module('myMod')。指令('myDir',['$compile',
函数($compile){
返回{
限制:'E',
替换:正确,
范围:{
类型:“@”,
瓦尔:“@”
},
链接:函数(作用域、元素、属性){
var newEl;
开关(范围类型){
案例“1”:
纽尔='';
打破
案例“2”:
纽尔='';
打破
}
替换为($compile(newEl)(scope));
}
};
}
]);
})();
HTML:


{{item.name}
当我检查元素时,我可以看到它返回值:“这是一个文本框”,我确信我已经接近了,但我想将模型/对象“绑定”到指令,而不是值/文本:

<input type="text" class="k-textbox ng-scope" k-ng-model="This is a textbox text">

请随意编辑问题,如果你了解我正在努力实现的目标,它有助于使其他人更有意义。。。
谢谢

您不应该在那里使用插值指令,它将在
value
属性中添加评估值,而是直接使用
val
,这样
k-ng-model
将保留
val
$scope-value-reference的引用

switch (scope.type) {
    case "1":
        newEl = '<input type="text" class="k-textbox" k-ng-model="val"  />';
        break;
    case "2":
        newEl = '<input kendo-date-picker k-ng-model="val" />';
        break;
}
开关(scope.type){
案例“1”:
纽尔='';
打破
案例“2”:
纽尔='';
打破
}
switch (scope.type) {
    case "1":
        newEl = '<input type="text" class="k-textbox" k-ng-model="val"  />';
        break;
    case "2":
        newEl = '<input kendo-date-picker k-ng-model="val" />';
        break;
}