http://host/api
当我使用以下参数询问 api 时,我可以访问 JSON api,api URL 是
http://host/api&q=count_people&on=house&house_id=123433
api响应是:
{
people: "6"
}
api 像前面的例子一样工作,现在当我尝试在我的控制器中使用时,我有以下代码
//app.js
var app = app.module('myapp', ['ngResource']);
app.factory('API', function($resource) {
var API = $resource('host/api');
return {
get: function(o, q, params) {
s = API.get({on: o, q: q, house_id: params.id}, function(u) {
return u;
})
return s;
}
};
});
app.controller('myController', function($scope, API) {
$scope.ns = {
count_people: function() {
return API.get('house', 'count_people', {id: 123433});
}
};
});
在我的模板中,我有
<!-- mytemplate.html -->
<p>Total of people in house: {{ns.count_people().people}}</p>
但ns.count_people().people
从来没有被称为