0

I was trying to use promise from geocoder lattitude and langitude. that need to be trigger from the ng-init directive. but I was not able to use promise inside a function. plunker for example my ng-init look like this:

<div>Address {{ $index + 1 }}: {{ facility.address }}<span  ng-init="distance = maps(facility)" > distance = {{distance}}</span></div>

the whole code is inside a ng-repeat. since my codes are in ng-repeat i cannot use timeout. i think so span having ng-init is replaced with {} this. you can check that out in plunker. I don't know what is happening.

santhosh
  • 1,919
  • 3
  • 21
  • 33

1 Answers1

1

I took a look at your plunker and in your ng-init you assign your variable test to the result of the function test1 which return itself a Promise and you can't directly print a Promise object in an angular template.

As test is a Promise object, so you can use test.then(function (result) { /* ... */ }).

antoinestv
  • 3,286
  • 2
  • 23
  • 39
  • you meant i should not use promise. instead of that suggesting me to use .then >> am i correct – santhosh Mar 11 '16 at 12:27
  • In your case you can avoid using a promise, so don't use it. And if you have to use a promise, you should think of using `$q`instead of `Promise`, or you will have to manually launch a digest in your `then` (ex: `$timeout()` etc). Take a look at : https://docs.angularjs.org/api/ng/service/$q – antoinestv Mar 11 '16 at 12:31
  • wow awesome $q is also not working i tried. so i think i had to use timeot – santhosh Mar 11 '16 at 12:36
  • That's probably because you don't use $q properly. You can find examples here: http://jsfiddle.net/softwaredoug/z58vmdnn/ (that's not the promise itself that you can show in the template, but you can change the scope based on the results of a promise) – antoinestv Mar 11 '16 at 12:41