我怎样才能使TestService的工厂从POST请求返回的结果?还是使应用程序,工厂更新overallcontroller
内的一些细节$scope
多数民众赞成?
我怎样才能更新overallcontroller
从另一个控制器内的信息?
app.factory('testservice', ['$http', 'auth', function($http, auth) {
var o = {
posts : []
};
o.test = function() {
return $http.post('/poster', null, {
headers: {Authorization: 'Bearer '+auth.getToken()}
}).success(function(data){
console.log(Data);
});
};
return o;
}]);
app.controller('overallController', ['$scope', 'posts', 'testservice', 'auth','$interval',
function($scope, posts, testservice, auth, $interval) {
$scope.data = {cash:"12879999",location:"test2",gang:"None","username":"test",
xp: 1290,
health: 100,
wanted: 30,
energy: 90};
var databackground = function() {
console.log("logging...");
var t = testservice.test;
console.log(t);
}
databackground();
$interval(databackground, 30000);
}]);
例如HTML
<div class="main" ng-controller="overallController">
<section class="sides left" style="background:blue; height:100px;">
<ul>
<li ng-hide="isLoggedIn()"><a href="/#/login">Logg inn</a></li>
</ul>
</section>
<div ng-controller"othercontroller">
// call made from some code here
</div>
</div>
如果在MainCtrl控制器中调用它,并且overallcontroller持有$ scope.data info,那么在mainctrl中调用它时如何将结果传输到overallcontroller中? – maria
如果整体控制器需要这些数据,那么为什么要将该代码放在MainCtrl中,而不是放在overallcontroller中? –
,因为我觉得我应该在mainctrl范围内完成一些特殊的输入后调用更新后的数据。在页面上使用一个控制器而不是两个更好? – maria