2016-09-25 59 views
-2

我需要使用angular從Web端點獲取數據,然後它需要將其顯示給用戶。環境應該使用bower進行配置,使用grunt作爲任務管理器。如何使用角度從Web端點獲取數據?

我已經安裝了bower,angular和boostrap,頁面佈局完成。問題是,我如何從該端點獲取數據以顯示它? (它基本上與ID和名稱的列表)

謝謝

+0

什麼端點的回報? – Zeokav

+0

向端點api發出'get'或'post'請求,並對返回的數據做任何你想做的事情。什麼是Web端點返回的數據fromat。 –

+0

@Zeokav它返回名稱和ID爲 –

回答

2

嘗試使用角度的$ HTTP服務從端點檢索數據。 https://docs.angularjs.org/api/ng/service/ $ http#get

之後,在回調函數中,您將能夠使用端點中的數據並將數據保存到控制器中。

只是像往常一樣渲染它。

E.G:

$http({method: 'GET', url: 'your url as a string'}). 
    then(function(response) { 
     // here your response goes. Use it. 
     // in your case - your data will be in response.data 
     console.log(response.data); 
    }, function(response) { 
     // here is the error if requset failed. 
    });