javascript - 如何使用 angular.js 禁用输入框

标签 javascript jquery angularjs

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

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

在 Controller 中我有这个代码来禁用输入元素:

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

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

请帮忙。

最佳答案

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

关于javascript - 如何使用 angular.js 禁用输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17402294/

相关文章:

javascript - 使用模拟 $resource 在 AngularJS 中进行单元测试

javascript - 将鼠标悬停在 div 内的图像更改为另一个图像

jquery - 在jquery中分割html标签

javascript - 具有由每个项目 JS 重写的函数的全局对象?

html - 使用 getText() 验证元素在使用 typeahead 时返回空字符串

javascript - 为什么我的输入焦点指令不再起作用?

javascript - 为什么ajax调用缓存表单数据?

javascript - 如何更改数据表中关键事件的分页?

php - 将访问者从我的页面重定向到其他域(eshop)并在购买产品后将其重定向回来?

javascript - Highcharts Columnrange数据标签高低不同颜色