Angularjs指令用于单个控制器内的几个ng-options

时间:2017-08-07 20:01:07

标签: angularjs angularjs-directive

Angularjs新手。我有一个控制器。

<div ng-controller='ConfigurableInputController as configurableInput'>

以上控制器声明中的几个ng-options:

<select class="dropdown-1" 
                ng-show="configurableInput.selectedCriteria === 'Channel'" 
                ng-model="configurableInput.selectedChannel1" 
                ng-options="channel for channel in configurableInput.channelList">
            <option value="">--Please select the channel--</option>
        </select>

        <select class="dropdown-2" 
                ng-show="configurableInput.selectedCriteria === 'Channel'" 
                ng-model="configurableInput.selectedChannel2" 
                ng-options="channel for channel in configurableInput.channelList">
            <option value="">--Please select the channel--</option>
        </select>

        <select 
            class="dropdown-1" 
            ng-show="configurableInput.retailArray.length > 0" 
            ng-model="configurableInput.selectedRetailLocation1" 
            ng-options="item1.retailLocation1 as item1.retailLocation1 for item1 in configurableInput.retailLocArray | filter : { retailLocation1 : '!!' }">
            <option value="">--Please select Store Id--</option>
        </select>

        <select 
            class="dropdown-2" 
            ng-show="configurableInput.retailArray.length > 0" 
            ng-model="configurableInput.selectedRetailLocation2" 
            ng-options="item2.retailLocation2 as item2.retailLocation2 for item2 in configurableInput.retailLocArray | filter : { retailLocation2 : '!!' }">
            <option value="">--Please select Store Id--</option>
        </select>

我如何拥有一个可以重复用于所有上述4 ng选项的指令?

0 个答案:

没有答案