【发布时间】:2015-10-07 17:26:48
【问题描述】:
我是 Angular 的新手,我正在尝试将我的数据传递到前端。 在控制台中,它以“200 OK 状态(缓存)”作为回答,但不是我查看了类似这样的各种问题,但我无法完成。
.factory('caseFactory', function($http, $stateParams) {
return{
getCases : function() {
return $http({
url: 'assets/app/work/detail/' + $stateParams.caseID + '.json',
method: 'get'
})
}
}
})
.controller('workDetail', ['$scope', 'caseFactory',
function($scope, caseFactory) {
$scope.case = [];
caseFactory.getCases().success(function(data){
$scope.case = data;
console.log('well it works though');
alert(JSON.stringify(data));
})
.error(function(data) {
console.log('sorry')
});
}])
我什至不确定哪个表达式是正确的 atm,所以我只是尝试了 一些,并希望它会成功.. 至少一次。
.state('detail', {
url:'/detail/:caseID',
templateUrl: 'assets/app/work/detail/detail-view.html',
controller: 'workDetail',
controllerAs: 'detail'
})
<div class="detailCover">
<div class="detailCoverText">
<h3>Headline{{ detail.title }}</h3>
<div class="category">Kategorie{{detail.category}}</div>
{{ detail.case.title }}
{{ case.title }}
</div>
</div>
【问题讨论】:
标签: javascript json angularjs get