) 我在将 ajax 答案呈现到 View 时遇到了麻烦。
有我的看法
<div id="content" layout:fragment="content" ng-app="Messages">
<div class="twitter" ng-repeat="tweet in tweets" ng-model="tweets">
<span> <input type="checkbox" name="active"
ng-checked="isSelected($event)" class="publishCheckbox"
data-id="{{tweet.socialId}}" ng-controller="publishController"
ng-click="publishMessage($event)" /></span> <span>{{tweet.createdAt}}</span>
<span>{{tweet.network}}</span> <span>{{tweet.text}}</span>
</div>
<button type="button"
class="btn btn-default navbar-btn twitter-posts"
ng-controller="getMoreTweets" ng-click="onloadTweets($event)">Get
more tweets</button></div>
这是我的控制器
var app = angular.module("Messages", []);
app.controller('getMoreTweets', function($http, $scope, $element) {
$scope.tweets = [];
$scope.onloadTweets = function(e) {
var buttonElement = angular.element(e.target);
var socialId = buttonElement.prev().prev().children().children().attr(
"data-id");
var dataString = {
'socialId' : socialId
};
$http({
method : 'GET',
url : "/infoboard/getMoreTweets",
params : dataString
}).success(function(data, status, headers, config) {
$scope.tweets = data;
console.log(data);
console.log($scope.tweets);
console.log("All correct");
}).error(function(data, status, headers, config) {
console.log("Something went wrong");
});
};
$scope.isSelected = function(e) {
return $scope.selected.indexOf(angular.element(e.target)) >= 0;
};
});
数据应该来自服务器,但没有呈现到视图中(我做错了什么?