I use angular-ui.bootstrap.typeahead and I want to update it's model when a promise resolves.
I use the typeahead-on-select attribute like this
typeahead-on-select="select($item,$model))"
In select($item,$model) some asynchronous stuff is going on, and when a promise resolves I want to set the value of the model based on the result.
promise.then(function (result) {
$model.name = result;
console.log($model); // <-- $model IS updated but the view doesn't react on it
}
I have tried using $apply different places, but it doesn't seem to work (errors).
How do I get the view to notice I have updated the model?
typeahead-on-select($item, $model, $label)was the typeahead model. But it's probably the model for the specific item in the list. Updating this model was not what I was trying to do. Now I send the name of the model variable to the function and update the model like this$scope[modelName] = result. Probably not the best solution, but it's working - I can move on :)