1

我在我的項目中使用bootstra-multiselect以及angularjs。在測試期間,我發現,「selected」屬性名稱在這兩者之間發生衝突。以下是我的多選指令的HTML標記。在使用bootstrap-multiselect並與angularjs「selected」指令衝突的多選下拉菜單中使用「selected」屬性衝突

<select id="example-getting-started" multiple="multiple" name="multiselect[]" data-dropdownmultiselect>  
    <option data-ng-repeat="option in options" value="{{getOptionId(option)}}" data-ng-attr-selected="{{isOptionSelected(option)}}" data-ng-bind-template="{{option.name}}"></option> 
</select> 

我發現,data-ng-attr-selected="{{isOptionSelected(option)}}"是沒有得到通過angularjs編譯。看起來像角js「ng-selected」指令正在應用,而不是我所需的普通屬性。

如何解決這個問題?我不想更改代碼或bootstra-multiselect或angularjs以避免將來的維護。 Angularjs中有什麼可以停止運行預定義的「ng-selected」指令?

以下是plunker代碼演示這個問題 Angularjs and conflict of directive name with other module

回答

1

你可以使用ng-selected="expression"這將增加selected屬性與當前select選項selected價值,我不明白爲什麼你正在使用ng-attr,而你這樣做可以控制使用ng-selected="isOptionSelected(option)"

標記

<select id="example-getting-started" multiple="multiple" name="multiselect[]" data-dropdownmultiselect>  
    <option data-ng-repeat="option in options" value="{{getOptionId(option)}}" 
    ng-selected="isOptionSelected(option)" 
    data-ng-bind-template="{{option.name}}"></option> 
</select> 

Working Plunkr

讓我知道如果你想在它別的,謝謝:)

+0

感謝您的解決方案。好東西,它在plunker中工作,但是當我試圖在我的代碼庫中移動相同的代碼時,我確實看到表達式正在執行,但屬性名稱仍然是「data-ng-selected」,如下所示,不知道爲什麼? joy 2015-04-05 17:51:00

+0

做的角度版本的PLUNK和你的代碼是相同的?我不認爲這會影響'data-ng-selected =「選擇」'...當ng選擇的表達式爲真時,我會一直添加'selected =「selected」' – 2015-04-05 18:56:21

+0

我正在使用angular v 1.3 0.0。我意識到,與我的版本,我需要返回true/false。 – joy 2015-04-19 02:14:36