Michael Michael - 1 year ago 92
AngularJS Question

Show returned result from controller in template

I call function from HTML and I want to display returned result.

Here is html code:

<td ng-init="'damages = list.getDamageEvents(soData.damagesId)'">

here is function in controller:

self.getDamageEvents = function (reviewsId) {
var t;
return $http.get(config.baseUrl + "api/DamageEvent/GetEventsByReviewsId/" + reviewsId).then(function (result) {
return t

the getDamageEvents() function return some string.

But in template view I don't see any returned result.

EDIT: I need to access getDamageEvents function as isolate scope.

Any idea why I can't see returned result?

Answer Source

$http.get return a promise, so you can't return a result at the end of your function getDamageEvents, instead you should affect your result to a variable called damages in the success callback like this :

self.getDamageEvents = function (reviewsId) {
   $http.get(config.baseUrl + "api/DamageEvent/GetEventsByReviewsId/" + reviewsId)
   .then(function (result) {
     self.damages = result.data;

Then you can access the damages variable in your view

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download