这是我的代码如何在AngularJS中使用rest api获取列表数据。在这里我有问题我无法在 sp 中绑定列表数据。我发现无法调用控制器。
<pre lang="Javascript">
var myAngApp = angular.module('SharePointAngApp', []);
alert('sss');
myAngApp.controller('spCustomerController', function ($scope, $http) {
$http({
method: 'Post',
url: appWebUrl + "/_api/SP.AppContextSite(@TargetSite)/web/lists/getByTitle('InfoList')/items?@TargetSite='" + targetSiteUrl + "'",
headers: { "Accept": "application/json;odata=verbose" }
}).success(function (data, status, headers, config) {
$scope.customers = data.d.results;
}).error(function (data, status, headers, config) {
});
$(document).ready(function () {
var appWebUrl = "";
var targetSiteUrl = "";
var ready = false;
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var param = params[i].split("=");
switch (param[0]) {
case "SPAppWebUrl":
appWebUrl = decodeURIComponent(param[1]);
break;
case "SPHostUrl":
targetSiteUrl = decodeURIComponent(param[1]);
break;
}
}
// load the request executor script, once ready set a flag that can be used to check against later
$.getScript(appWebUrl + "/_layouts/15/SP.RequestExecutor.js", function () {
ready = true;
});
});
});
</pre>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre lang="HTML">
<div ng-app="SharePointAngApp" class="row">
<div ng-controller="spCustomerController" class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Title</th>
<th>Employee</th>
<th>Company</th>
</tr>
<tr ng-repeat="customer in customers">
<td>{{customer.Title}}</td>
<td>{{customer.Employee}}</td>
<td>{{customer.Company}}</td>
</tr>
</table>
</div>
</div>
</pre>