相关疑难解决方法(0)

在AngularJS中有条件地应用属性的最佳方法是什么?

我需要能够根据范围内的布尔变量向元素添加"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中删除了,为什么会这样呢?

angularjs angularjs-directive

288
推荐指数
9
解决办法
27万
查看次数

什么时候使用ng-attr?

似乎使用直接属性和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属性?

angularjs

15
推荐指数
3
解决办法
3万
查看次数

AngularJS:将布尔值传递给指令

我无法将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)

任何帮助将非常感激.

angularjs angularjs-directive

12
推荐指数
3
解决办法
2万
查看次数

标签 统计

angularjs ×3

angularjs-directive ×2