2017-04-11 1 views
0

私は自分のコントローラ内のAPIにGet呼び出しを行います。オブジェクトの値にアクセスしたいのですがどうすればできますか?データバインディングを使用すれば値を見ることができますオブジェクト内の変数の値。コントローラ内の変数値にアクセスするngResource in angularjs

var app = angular.module("myApp",["ngResource"]); 
app.factory("myAppFactory",function($resource){ 
    return{ 
    Test: $resource("https://jsonplaceholder.typicode.com/users/:id", {id:"@id"}) 
    } 
}); 
app.controller("ctrl",function($scope,myAppFactory){ 
    var productDetailServer = myAppFactory.Test.get({ id: 1 }, function() { 
    }); 
    var aux=productDetailServer; 
    $scope.variable = productDetailServer; 
    console.log(productDetailServer); 
    console.log("the website\n"); 
    console.log(aux.website); 
    console.log("how do you access variable inside the response?"); 
    /* 
    How can I do something like this: 

    var website =productDetailServer.website 
    website should access the website within the productDetailServer object but 
    all I get is undefined, how do I assign the website propierty from the object to the variable? 
    Thanks 

    */ 
}); 

しかし、どのようにしてコントローラから変数の値にアクセスできますか?おかげ

は、私はより良い私が何を意味するのかを説明するPlunkerをした:

https://plnkr.co/edit/lSsxdbgc5eRXzuIV64ND?p=preview

答えて

関連する問題