如何使用angular.js禁用输入框 [英] How to disable an input box using angular.js

查看:236
本文介绍了如何使用angular.js禁用输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此字段用于编辑视图和创建视图

I am using this field for an edit view and a create view

<input data-ng-model="userInf.username"  class="span12 editEmail" type="text"  placeholder="me@example.com"  pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" required />

我有这段代码来禁用输入元素:

in the controller I have this code to disable the input element:

function($rootScope, $scope, $location, userService)
{

//etc 
    $(".editEmail" ).attr("disabled", disable);  // no idea how to do in angular
}

请帮忙。

推荐答案

使用 ng-disabled 或带有 ng-class 的特殊CSS类

Use ng-disabled or a special CSS class with ng-class

<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}"
/>

这篇关于如何使用angular.js禁用输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆