Angularjs 离子角度数据传递不正确
我正在从url检索json数据,如果我输出到控制台,数据就在那里。。但当我把它注入控制器时,它就不工作了。我做错了什么Angularjs 离子角度数据传递不正确,angularjs,ionic-framework,Angularjs,Ionic Framework,我正在从url检索json数据,如果我输出到控制台,数据就在那里。。但当我把它注入控制器时,它就不工作了。我做错了什么 angular.module('starter.notifications', []) .factory('Notifications', function($http) { return { getAll: function() { return $http.get(link).then(function(response){ c
angular.module('starter.notifications', [])
.factory('Notifications', function($http) {
return {
getAll: function()
{
return $http.get(link).then(function(response){
console.log(response.data);
notifications = response.data;
return notifications;
});
}
}
我的控制器
.controller('NotificationsCtrl', function($scope, $state, Notifications) {
$scope.notifications = Notifications.getAll();
})
$scope.notifications为空。所以我不明白为什么这不起作用
更新:
所以我现在让它传递数据。。但我想我不知道怎么用它
正确/工作代码
getAll: function()
{
notifications = ($http.get(link).then(function(response){ return response.data}));
return notifications;
}
所以现在在我的控制器中,当我
console.log(notifications);
我明白了
那么我如何使用这些数据呢?我想要的数据数组就在那里。。。但是我不能得到它。我想我可以用
notifications.value但这不起作用我认为错误在于您的工厂正在发送两条返回语句。请将代码更改为
getAll: function()
{
var temp = $http.get(link).then(function(response){
console.log(response.data);
var notifications = response.data;
return notifications;
});
}
需要传递多个参数。最初,我只传递有效的响应数据、状态、标题、配置。我做了一些调整。。现在进入下一个问题。访问data.now要显示json中的所有数据,需要使用ng repeat指令,如{{notification.value}},否则如果不想显示完整的数据,则需要通过{{notifications[0].value}访问它
notifications = ($http.get(link)
.success(function(data, status, headers, config){
console.log(data);
return data;
})
.error(function(err) {
return err;
})
);
return notifications;