0

So I want to create a directive that embeds the angular ui-select directive, with my configuration. However when I pass my variable to ng-model it is not updated in the parent. Only in the ui-select itself. I was assuming that calling '=' in an isolated scope would lead to two way data-binding. Do I have to call $apply somewhere? Any help?

so my html usage should look like this:

<interpreter-search ng-model="booking.interpreterId" id="field_interpreter"/>

directive:

angular.module('omserviceApp')
.directive('interpreterSearch', ['InterpreterSearch' , function (InterpreterSearch) {
    return {
        restrict: 'E',
        scope:{
          interpreterId: '=ngModel'
        },
        link: function (scope, element, attrs) {

            scope.refreshInterpreters = function (query) {
                InterpreterSearch.query({query: query}, function (result) {
                    scope.interpreters = result;
                }, function (response) {
                    if (response.status === 404) {
                        scope.interpreters = [];
                    }
                });
            };

        },
        templateUrl: 'scripts/components/entities/interpreter/interpreter-search.html'
    }
}]);

template:

<ui-select ng-model="interpreterId">
<ui-select-match placeholder="Find an interpreter...">
    <span ng-bind="interpreterId"></span>
</ui-select-match>
<ui-select-choices repeat="interpreter.id as interpreter in (interpreters | filter:  $select.search)"
                   refresh="refreshInterpreters($select.search)"
                   refresh-delay="0">
    <span ng-bind="interpreter | interpreterHtml"></span>
</ui-select-choices>

0 Answers0