0
這是我的指令來顯示一個輸入字段:如何使對象/屬性顯示在指令中?
JS:
.directive('isField', function() {
return {
restrict: 'EA',
template: '<div class="form-group">' +
'<label class="col-sm-2 control-label">{{prop}}</label>' +
'<div class="col-sm-10">' +
'<label ng-if="obj.prop" class="control-label" style="font-weight:normal;">Yes</label>' +
'<label ng-if="!obj.prop" class="control-label" style="font-weight:normal;">No</label>' +
'</div>' +
'</div>',
scope: {
obj: "@obj",
prop: "@prop",
},
controller: function(){
},
link: function(scope,elem,attr,ctrl){
}
};
})
HTML:
<is-field obj="pano" prop="isOutRoom" class="ng-isolate-scope">
<div class="form-group">
<label class="col-sm-2 control-label ng-binding">isOutRoom</label>
<div class="col-sm-10">
<!-- ngIf: obj.prop -->
<!-- ngIf: !obj.prop -->
<label ng-if="!obj.prop" class="control-label ng-scope" style="font-weight:normal;">No</label>
<!-- end ngIf: !obj.prop -->
</div>
</div>
</is-field>
但obj.prop
沒有被評估,該指令顯示No
甚至當obj.prop
是true
。
樣品JSON:
pano:
{
"objectId": "566f915b00b0814d65fa12e0",
"isVirtualRoom": true,
}
我做得不對的指令的scope:
一部分?
試試這個 **範圍:{ obj:「= obj」, prop:「= prop」, } ** – Vivek