我想將角度選擇列表包裝成一個簡單的指令,這將允許我一起繪製選擇列表和標籤。自定義AngularJS指令將不會正確繪製
我遇到了兩個問題。
1.選擇列表中的選項沒有被填充
2. ngModel屬性,我嘗試向下傳遞到我的指令,不,我在我的指示標記屬性指示數據填充。
var myApp = angular.module('myApp',[]);
myApp.controller('Ctrl', ['$scope', function($scope){
$scope.currentBusinessStructure = '';
$scope.businessStructure = ['Monarchy', 'Corporation'];
}]);
myApp.directive('specialSelect', [function(){
return {
restrict: 'A',
transclude: true,
template:
'<label ng-transclude></label> \
<select ng-model="currentBusinessStructure" ng-options="{{ngOptions}}" class="form-control"> \
</select> \
<br>INSIDE MY DIRECTIVE: {{ngModel}} : {{ngOptions}}',
scope: {
ngOptions: '@ngOption',
ngModel: '='
}
};
}]);
請看看我的fiddle here
我相信你需要使用ngOptions: '= ngOption'沒有@ – Scott 2014-09-22 17:53:06
對不起,完全誤讀了。我認爲你的ngOptions表達式是錯誤的。它需要是我認爲完全合格的表達。請查看此文檔。 https://docs.angularjs.org/api/ng/directive/select – Scott 2014-09-22 18:08:46