【发布时间】:2014-04-22 04:12:23
【问题描述】:
在服务器上,我有以下简单的 Go REST 功能:
func GetFoo(w http.ResponseWriter, r *http.Request){
res1D := &Response1{
Page: 101,
Fruits: []string{"apple", "peach", "pear"},
}
res1B, _ := json.Marshal(res1D)
w.Header().Set("Content-Type", "text/json; charset=utf-8")
w.Write(res1B)
}
type Response1 struct {
Page int
Fruits []string
}
在我的 index.html 上,我的 AngularJS 代码是:
<div ng-controller="SecondCtrl">
{{allFoo}}
<div ng-repeat="foo in allFoos">
{{foo}}
</div>
还有我的 AngularJS 控制器:
function SecondCtrl($scope, Restangular){
var foos = Restangular.all('rest/foos');
foos.getList().then(function(foo) {
$scope.allFoos = foo;
});
};
当 index.html 被渲染时,对于 {{allFoos}} 我看到了:
{"0":101,"1":["apple","peach","pear"],"Page":101,"Fruits":["apple","peach","pear"],"route":"rest/foos","parentResource":null,"restangularCollection":true}
对于重复的 AngularJS div,对于 {{foo}},我得到:
101
["apple","peach","pear"]
["apple","peach","pear"]
101
true
rest/foos
我的目标是只显示 Response1 的“页面”字段。 我在重复 div 中尝试了 {{foo.Page}},但随后重复 div 没有显示任何内容,并且我没有看到错误。
【问题讨论】: