Basically what I want to do, is to assign some model value from function call that resolves promise. Like so
value = someFun()
This is a service from which I call this function
app.factory('SomeService', function($q) {
return {
someFun: function() {
var d = $q.defer();
try {
d.resolve("hi");
} catch (e) {
d.reject(e);
}
return d.promise.then(function(text){
return text;
});
}
};
});
Here is the HTML code
<div ng-init="value = 'yes'">
<pre>{{value |json}}</pre>
</div>
<button type="button" ng-click="value = someFun()">click me</button>
And this is in the controller
$scope.someFun = SomeService.someFun;
Here is plnkr
http://plnkr.co/edit/qO5ofBXZDsi3cS3bBnT8
Right now it returns an empty object. What is wrong?
EDIT: As already answered below, yes this is one way, but let's say I want to call SomeService.someFun in ngRepeat?
EDIT2: HERE IS THE ANSWER -> Angular UI Bootstrap modal inside ngRepeat