drop down menu - AngularJS Dropdown Directive Set Selected Item Through Two Way Binding -


i have angularjs dropdown directive. want able pass id of item want selected attribute of directive. this:

<dropdown selected-item-id="ctrl.selecteditemid"></dropdown>   

i implemented , it's not working. if display value of itemid on directive code, can see right value, dropdown selection not update. here's relevant code:

(function () {  	'use strict';  	var dropdown = function ($state, service) {  		return {  			restrict: 'e',  			replace: true,  			templateurl: '/dropdown.html',  			scope: {  			    selecteditemid:"="  			},  			link: function (scope, elem, attr) {                service                  .getitems()                  .then(function (items) {                      scope.items = items;                   });  			}  		};  	};  	dropdown.$inject = ['$state', 'service'];  	angular.module('app').directive('dropdown', dropdown);  })();
<select class="form-control"          ng-model="selecteditemid"          ng-options="item.id item.name item in items">      <option value="" selected disabled>select item</option>  </select>

like said, if display selecteditemid on directive template (e.g. 1 of options) see right id value, dropdown selection doesn't change.

any thoughts?

edit: had typo (happened when typing code, actual code on editor correct) on dropdown's property, item-id selected-item-id

you not binding selected value item-id think according html code. binding selected value selected-item-id.

try changing html this:

 <dropdown selected-item-id="ctrl.selecteditemid"></dropdown> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -