Question: I have an angularjs dropdown directive. I want to be able to pass the id of the item I want to be selected as an attribute of the directive. Something like this:

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

```

I implemented this and it's not working. If I display the value of itemId on the directive code, I can see the right value, but the dropdown selection does not update. Here's the relevant code:

```js
(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);
})();
```

```html
<select class="form-control"
        ng-model="selectedItemId"
        ng-options="item.id as item.name for item in items">
    <option value="" selected disabled>Select an item</option>
</select>
```

Like I said, if I display the selectedItemId on the directive template (e.g. as one of the options) I see the right id value, however the dropdown selection doesn't change.

Any thoughts?

**EDIT:**
I had a typo (happened when typing the code, the actual code on my editor is correct) on the dropdown's property, item-id to selected-item-id

Answer: 
You are not binding selected value to item-id as you think according to your html code. You are binding selected value to selected-item-id.

Try changing your html to this:

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

```
Looks like you might be having a race condition on the $digest cycle. If you call $apply() from your service callback on the first version of your code it should work. However, you will have the side effect that from time to time angular will complain about an $apply being already in progress so the second version of your code should do the trick.