与DOM一样,指令'cur'将使用jQuery
更改DOM,但不会保存在范围内。
如果我想重写DOM,我可以编译并替换DOM。代码是这样的:$('#main').html($compile($('#main').html())($scope))
但是,有更好的方法可以直接编译DOM吗?
<div id="main">
<div class="fl item" ng-class="cur == 1? 'cur':''" cur>111</div>
<div class="fl item" ng-class="cur == 2? 'cur':''" cur>222</div>
<div class="fl item" ng-class="cur == 3? 'cur':''" cur>333</div>
<div class="fl item" ng-class="cur == 4? 'cur':''" cur>444</div>
<textarea name="" id="msg" cols="30" rows="10" ng-bind="msg">
</textarea>
</div>
app.directive('cur', function(){
return function(scope,ele){
ele.click(function(){
ele.addClass('cur').siblings().removeClass('cur');
})
}
});
答案 0 :(得分:0)