我已阅读角度材质文档,并且它们具有readonly属性以禁用该元素。但是我无法让它工作,我还可以使用任何其他Angular Material方法吗?我想默认禁用元素。 main.html中
<div layout="row" layout-margin>
<md-input-container flex="100" class="notifyUser-chips">
<label>Bcc</label>
<br>
<md-chips flex="100"
ng-model="notifyCtrl.bcc"
name="email"
readonly="true">
</md-chips>
<p style="color:red" ng-show="patternError">An email must contain a-z, A-Z, 0-9, or _ characters</p>
</md-input-container>
</div>
答案 0 :(得分:0)
我在this fiddle复制了您的代码,对我来说它工作正常。
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<div layout="column" layout-margin>
Readonly
<md-chips ng-model="bcc"
name="email"
readonly="true">
</md-chips>
Not readonly
<md-chips ng-model="bcc"
name="email">
</md-chips>
</div>
</div>
</div>
var myApp = angular.module('myApp',['ngMaterial']);
myApp.controller("MyCtrl", ["$scope","$rootScope", function($scope,$rootScope){
$scope.bcc = ['Broccoli','Cabbage','Carrot'];
}
]);
检查角度材料和角度版本。
答案 1 :(得分:0)
如果您有ng-model,角度材质将始终将它们视为可编辑。另外在文档中说如果没有提供ng-model,则芯片将自动标记为只读https://material.angularjs.org/latest/api/directive/mdChips。
所以这是修复......
<md-chips flex="100">
<md-chip ng-repeat="chip in notifyCtrl.bcc"
name="email"
readonly="true">{{chip}}
</md-chip>
</md-chips>