Angularjs - Adding an attribute directive to a select clobbers ng-options -
i'm trying add attribute directive select using ng-options:
<select ng-model="item.subcategory" ng-options="subcategory.name subcategory.name subcategory in getsubcategories(item.category)" monitor></select>
at moment, doesn't meaningful:
angular.module("monitor", []) .directive("monitor", function() { var directive = { restrict: "a", scope: { }, controller: function($scope) { console.log("i exist"); } }; return directive; });
the directive seems working, see "i exist" per item uses directive, select loses options.
with directive in place, can see in html option select:
<option value="?" selected="selected"></option>
as opposed this, when not using directive:
<option value="0" selected="selected">cats</option> <option value="1">dogs</option>
why might directive breaking ng-options?
thank you.
there potentially several issues here, either of cause of problem.
according angularjs developer guide on directives:
if multiple directives on same element request new scope, 1 new scope created.
you creating new isolate scope on directive overriding scope other directives, including ng-options.
also, should keep in mind controller argument creates new controller shared other directives:
controller constructor function. controller instantiated before pre-linking phase , shared other directives (see require attribute). allows directives communicate each other , augment each other's behavior.
unless want use directive share data other directives, should avoid creating controller.
is there reason why directive can't accomplish needs in simple link function?
Comments
Post a Comment