我需要能够根据范围内的布尔变量向元素添加"contenteditable".
使用示例:
<h1 attrs="{'contenteditable=\"true\"': editMode}">{{content.title}}</h1>
Run Code Online (Sandbox Code Playgroud)
如果$scope.editMode
设置为,则会导致将contenteditable = true添加到元素中true
.有没有一些简单的方法来实现这样的ng-class属性行为?我正在考虑写一个指令并分享,如果没有.
编辑: 我可以看到我提出的attrs指令和ng-bind-attrs之间似乎有一些相似之处,但它在1.0.0.rc3中删除了,为什么会这样呢?
似乎使用直接属性和ng-attr-*
指令做同样的事情.例如,以下呈现等效:
<div ng-attr-id="{{ 'object-' + value }}">ID</div>
<div id="{{ 'object-' + value }}">ID</div>
Run Code Online (Sandbox Code Playgroud)
我ng-attr-*
什么时候应该使用,何时应该使用直接HTML属性?
我无法将boolean值传递给我的指令.
这是我的HMTL:
<city-zip city="clientCity" zip="clientZip" requiredParam="'true'"></city-zip>
Run Code Online (Sandbox Code Playgroud)
指令:
.directive('cityZip', function() {
return {
restrict: 'E',
templateUrl: '../templates/templateCityZip.html',
scope: {
city: '=',
zip: '='
},
controller: function($scope) {}
}
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.