javascript - Unable to bind data to scope object after service call using $RESOURCE in typescript AngularJS -
i pulling data api , trying bind variable , have debugged code getting data api not getting binded scope object here code
service:
module application.common { angular.module("common.service", ["ngresource"]) export class dataaccessservice { static $inject = ["$resource"]; /// avoid minificaton errors i.e prameters thgar use defines , should in order. constructor(private $resource: ng.resource.iresourceservice,private $http:ng.ihttpservice) { } getproductresource() { return this.$resource("http://localhost:50000/api/values/getproducts", { 'query': { method: 'get', isarray: false } }).get().$promise.then(function (response) { var obj = new product(); //debugger; obj.title = response.title; obj.showimage = response.showimage; obj.products = response.objdetails; return obj; }); } } angular.module("common.service",['ngresource']).service("dataaccessservice", dataaccessservice); }
here controller code calling service , consuming
class productlistctrl1 { obj: iproduct; static $inject = ["dataaccessservice"]; constructor(private dataaccessservice: application.common.dataaccessservice) { this.obj = new product(); dataaccessservice.getproductresource().then(function (response) { alert('1'); debugger; this.obj = response; // i'm getting response here properties }); alert('2 ' + this.obj.title); // alert firing first rather alert 1 this.obj.title = "product list type script11"; // getting binded ever properties i'm binding here loaded } } var app1 = angular.module("productmanagement1", ['ngroute', 'ngresource','common.service']); app1.controller("productlistctrl1", productlistctrl1);
entity:
interface iproduct { title: string; showimage: boolean; products: productdetails[]; } class product implements iproduct { title: string; showimage: boolean; products: productdetails[]; }
as per comments attaching response object
$promise:d $$state:object __proto__: object $resolved:true objdetails:array[3] showimage:false title:"tetsing typescropit" __proto__: object
Comments
Post a Comment