我正试图增强我们的指令。它曾经是一个输入类型='submit'class =“btn”元素,并且该指令替换为:“true”。我已经改变了模板,该指令于以下内容:AngularJs:在指令中对输入元素应用ng-class
<input type="submit" value="{{value}}" id="btnChoose"
ng-class="{{ngClass}}"
style="width: 85% !important; margin-top: 0;"
class="btn_file_select" ng-click="click()" />
(显示HTML的顶部)。我将replace更改为false,并将ngClass:'@'添加到指令中。
在我的表单中,我将ng-class设置为某些东西,并且在使用Dev检查元素时可以看到它。工具。我也可以看到,在我的按钮中添加了相同的ng-class表达式。但是,它不起作用,并没有被评估。
我应该如何正确地更新我的指令,以便能够在窗体的父级div上接收ng-class属性并将其传递给我的按钮?
样品现在的形式使用此指令:
<data-desc:type ng-class="{greenText: (currentSalespoint['lRemoteS' + n] == 0 && metaData.layOuts['dlrs' + n] > 0)}"
title="{{ '@String.Format(Labels.selectX, Labels.printer)'}}"
do-search="popup()"
value="{{currentSalespoint['lRemoteS'+ n] == 0 ? (metaData.layOuts['dlrs' + n]==0?'@String.Format(Labels.selectX, Labels.printer)':metaData.layOuts['dlrs' + n + 'Text']) : currentSalespoint['lRemoteS'+ n + 'Text']}}"
param="layouts"
filter-by="Remote Printer"
message="@String.Format(Labels.selectX, Labels.printer)"
selected="currentSalespoint['lRemoteS'+ n]" descrip-value="descrip" type-value="'lRemoteS'+ n"
description="currentSalespoint['lRemoteS'+ n
+ 'Text']"></data-desc:type>
和指令目前在顶部以下内容:
return {
restrict: 'E',
transclude: true,
replace: false,
scope: {
title: '@',
message: '@',
param: '@',
selected: '=',
description: '=',
value: '@',
descrip: '=',
type: '=',
ngClass: '@',
doSearch: '&',
filterBy: '@?'
},
你能告诉你的指令的代码示例? –
我编辑了我当前的帖子以显示当前使用情况的示例。 – Naomi