Angular自定义指令不能将value更改为ng-model
angular custom directives cannot change value to ng-model
我是angular新手,我已经为jquery时间选择器插件创建了一个自定义指令,这个插件不绑定ng-model
我的代码是控制输出,它说未定义
please check out
<table class="table table-bordered">
<thead>
<tr>
<th>Time From</th>
<th>Time To</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" ng-model="table.row1" size=6/ disabled>
</td>
<td>
<input type="text" ng-model="table.dup_row1 " size=6 timepicki/>
{{dup_row1}}
</td>
</tr>
</tbody>
</table>
,我的模块是
var app = angular.module('myApp', []);
app.directive('timepicki', [
function() {
var link;
link = function(scope, element, attr, ngModel) {
element.timepicki();
};
return {
restrict: 'A',
link: link,
require: 'ngModel'
};
}
])
app.controller('ctrl', function($scope) {
$scope.table={}
$scope.table.row1 = "00:00"
$scope.submit=function(){
console.log($scope.table.dup_row1)
}
});
这是制作自定义指令的正确方式吗?
任何帮助都是感激的,
MY PLUNKER LINK http://plnkr.co/edit/ZHYvUABqHh1MVF9APrR7?p=preview
Thanks in advance
插件的on_change属性的使用OnSelect no exist in Plugin.
app.directive('timepicki', function() {
return {
require: 'ngModel',
link: function(scope, el, attr,ngModel) {
$(el).timepicki({
on_change: function(dateText) {
dateFormat: 'hh:mm a',
scope.$apply(function() {
ngModel.$setViewValue(dateText);
});
}
});
}
};
})
相关文章:
- C#asp.net mvc Set CheckBoxFor已检查的具有Model Value的属性
- 从 Javascript 中设置 ng-model name
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- 当与之关联的 ng-model 为 false 时,Angularjs 复选框值不会取消选中
- ng-model 绑定到选择标签生成的空默认值
- 对象不能在angularjs ng-model中访问
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- ng-repeat不绑定ng-model对象数组
- AngularJS:ng-model 绑定在使用 jQuery 更改时不会更新
- 选择/选项 ng-model 未绑定 ng-selected
- Angular ng-model 将数据作为数组发送到 rails-api
- 为什么 AngularJS 在使用 ng-model 时不会在文本框上设置长度属性
- ui-bootstrap timepicker and ng-model value converter
- angular.js - update `ng-model` with text.value
- Difference between ng-model="xxx" and value="
- Angular.js - ng-model覆盖我的ng-value在文本输入
- Angular自定义指令不能将value更改为ng-model
- 在AngularJS中动态设置ng-model value为js变量的值
- 在ng-value和ng-model(Angularjs)中映射对象