Pra*_*obh 39 javascript jquery angularjs
我正在使用此字段进行编辑视图和创建视图
<input data-ng-model="userInf.username" class="span12 editEmail" type="text" placeholder="me@example.com" pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" required />
Run Code Online (Sandbox Code Playgroud)
在控制器中我有这个代码来禁用输入元素:
function($rootScope, $scope, $location, userService)
{
//etc
$(".editEmail" ).attr("disabled", disable); // no idea how to do in angular
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
Epo*_*okK 81
使用ng-disabled或带有ng-class的特殊CSS 类
<input data-ng-model="userInf.username"
class="span12 editEmail"
type="text"
placeholder="me@example.com"
pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"
required
ng-disabled="{expression or condition}"
/>
Run Code Online (Sandbox Code Playgroud)
Aru*_*hny 13
您需要使用ng-disabled指令
<input data-ng-model="userInf.username"
class="span12 editEmail"
type="text"
placeholder="me@example.com"
pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"
required
ng-disabled="<expression to disable>" />
Run Code Online (Sandbox Code Playgroud)
我为此创建了一个指令(角度稳定1.0.8)
<input type="text" input-disabled="editableInput" />
<button ng-click="editableInput = !editableInput">enable/disable</button>
app.controller("myController", function(){
$scope.editableInput = false;
});
app.directive("inputDisabled", function(){
return function(scope, element, attrs){
scope.$watch(attrs.inputDisabled, function(val){
if(val)
element.removeAttr("disabled");
else
element.attr("disabled", "disabled");
});
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
104622 次 |
最近记录: |