如何使用属性禁用日期字段
how to disable date field using attribute?
我正在尝试禁用字段using属性我不想使用指令作用域属性(=,@,&)我想使用属性属性禁用type='date'字段
这是我的代码
http://plnkr.co/edit/eJDRocLYkr8Krh84vFKY?p=preview
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.clickb=function(){
alert('dd')
$scope.disabletest=true;
}
});
app.directive('test',function(){
return {
restrict :'E',
scope:{},
template:'<input type="date" ng-disable="disabletest">',
link:function(s,e,a){
}
}
})
我正在发送指令中的disable
属性值,以禁用单击按钮时的字段。
我想使用属性属性
尝试此操作,将ng-disable
更改为ng-disabled
,并创建范围变量
var jimApp = angular.module("mainApp", []);
jimApp.controller('mainCtrl', function($scope){
$scope.disabletest = false;
$scope.clickb=function(){
$scope.disabletest=!$scope.disabletest;
};
});
jimApp.directive('test',function(){
return {
restrict :'E',
template:'<input type="date" ng-disabled="disable">',
link:function(s,e,a){
a.$observe('disable', function(value) {
s.disable = s.$eval(a.disable);
});
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<div ng-app="mainApp" ng-controller="mainCtrl">
<button ng-click='clickb()'>btn</button>
<test disable='{{disabletest}}'></test>
</div>
应该是
ng-disabled="expression"
index.html
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
<script src="app.js"></script>
</head>
<body >
<div ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<button ng-click='clickb()'>btn</button>
<input type="date" ng-disabled='disabletest'>
</div>
</body>
</html>
into指令,您必须指定一个属性来获得disabletest值
虽然您真的不应该使用$parent,但更改作用域是Jimbrooism建议的最佳解决方案。这是不修改范围的解决方案。更改为:
template:'<input type="date" ng-disabled="$parent.disabletest">',
http://plnkr.co/edit/ZBKv63aroXrao7GO9P2u?p=preview
相关文章:
- 如何使toLocalDateString中的日期字段可选
- 如何使用属性禁用日期字段
- JSP 中的“日期”字段存在问题
- 无法格式化keystone.js中的嵌套日期字段
- mongodb mongodump json日期字段解析错误
- 在日期字段上使用FTSearch
- crm 2011 javascript将日期字段设置为null
- 如何使用Javascript从HTML中的日期字段捕获日期
- ExtJS 5.1-如何将日期字段屏蔽为00/00/0000
- 用于比较日期字段的Javascript
- MVC 5-在所有浏览器中接受日期字段
- 在django中提交表单时更改日期字段值
- SQLite:从Phonegap/Cordova中的(文本)日期字段中选择日期和时间
- j查询验证单独的年、月、日的日期字段
- 从替代字段填充 jquery UI 日期选择器日期字段
- 在输入日期字段的多次迭代中加载日期选取器
- 在 podio 中将计算日期字段设置为 null(因此使用 javascript)
- SlickGrid:单元格中具有两个日期字段的复合编辑器
- MongoDB中的日期字段类型(并对其进行排序)
- MVC5 - 检查用于搜索日期字段的 2 个日期(文本框)之间的重叠