使用Golang REST服务中的AngularJS显示JSON字段

On the server, I have the following simple Go REST function:

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
}

On my index.html, my AngularJS code is:

<div ng-controller="SecondCtrl">
{{allFoo}}
<div ng-repeat="foo in allFoos">
    {{foo}}
</div>

And my AngularJS controller:

function SecondCtrl($scope, Restangular){

var foos = Restangular.all('rest/foos');

foos.getList().then(function(foo) {
    $scope.allFoos = foo;
});
};

When index.html is rendered, for {{allFoos}} I see:

{"0":101,"1":["apple","peach","pear"],"Page":101,"Fruits":["apple","peach","pear"],"route":"rest/foos","parentResource":null,"restangularCollection":true}

And for the repeat AngularJS div, for {{foo}}, I get:

101
["apple","peach","pear"]
["apple","peach","pear"]
101
true
rest/foos

My objective is to only display the "Page" field of Response1. I tried {{foo.Page}} in the repeat div, but then the repeat div does not display anything, and I do not see an error.

Use {{allFoo.Page}}. Your ng-repeat is looping over the values of allFoos, which is why you see Page's value, 101, in that list.