服务调用 - Angular JS

时间:2015-02-23 11:33:09

标签: javascript json angularjs web-services

我正在尝试从Webservice获取JSON对象并绑定到视图。当我从本地json读取而不是从Webservice调用中读取时,能够获取数据。

angular.module('MyCard1App', [	]).
controller('IndexViewController' , function ($scope, $http) {
//$http.get("data/data.json")
$http.get("http://localhost:9090/service/readerApp/Entity/1234567880?type=Activity&appId=1&userid=test")
    .success(function(response) {$scope.outages = response;});
	});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<table class="table table-striped table-bordered dataTable">
        <thead>
            <tr>
                <th>taskID</th>
                <th>categoryID</th>
                <th>category</th>
				<th>description</th>
				<th>status</th>
				<th>title</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="listItem in outages.entityData.taskDetailsResponse.actionItems.scope.tasks.arrayOfTaskItem">
                <td>{{listItem.taskID}}</td>
                <td>{{listItem.categoryID}}</td>
                <td>{{listItem.category}}</td>
				<td>{{listItem.description}}</td>
				<td>{{listItem.status}}</td>
				<td>{{listItem.title}}</td>
            </tr>
        </tbody>
    </table>

即使我尝试了其他一些选项,比如

angular.module('MyCard1App', ['ngResource']).
factory('Outage', function ($resource) {
	console.log("inside");
    return $resource('http://3.209.92.112:9090/service/readerApp/Entity/1234567880?type=Activity&appId=1&userid=test', {}, {
        query: {method: 'GET', params: {}, isArray: false}
    });
});

function IndexViewController($scope, Outage) {
	//console.log(Outage.query());
    //$scope.outages = Outage.query();
	Outage.query({}, function (data) {
		console.log(data.outages);
        $scope.outages = data.outages; 
    });
}

0 个答案:

没有答案