在服务器上,我具有以下简单的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 Controller :
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不会显示任何内容,并且看不到错误。

最佳答案

使用{{allFoo.Page}}。您的ng-repeat遍历了allFoos的值,这就是为什么您在该列表中看到Page的值101的原因。

09-11 02:09