首先,我希望通过codeigniter
方法在controller
页面中显示view
$http post
的json数据。
问题是我遇到了一些问题,然后我无法使其发挥作用。
代码:
.state('GetData', {
url: "/getdata",
templateUrl: base_url + "loadl/getdata",
data: {
pageTitle: 'Datapage'
},
controller: "Mycontroller",
resolve: {
deps: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'Myapp',
files: [
base_url + 'application/assets/js/controllers/Mycontroller.js'
]
});
}]
}
})
控制器:
angular.module('Myapp')
.controller('Mycontroller', function($rootScope, $scope, $http, $timeout) {
$http.get(base_url + "getData/show").
success(function(response) {
$scope.data1 = response.data;
});
});
CI控制器
public function show() {
echo '{"data":[{"sl_num":"1","name":"James","category":"1"}]}';
}
查看:
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" placeholder="John" class="form-control" ng-model="data1.name" />
</div>
答案 0 :(得分:1)
根据我的回答,我会工作
angular.module('Myapp')
.controller('Mycontroller', function($rootScope, $scope, $http, $timeout) {
$http.get(base_url + "getData/show").
success(function(response) {
console.log(response);
$scope.data1 = response.data[0].name;
console.log($scope.data1);
});
});
查看:
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" placeholder="John" class="form-control" ng-model="data1" />
</div>