所以我一直在摆弄angularjs指令。我想在这里完成的只是触发按钮点击拉动数据。我该如何处理这个过程。
formApp.directive('task', function($http) {
var directive = {};
directive.restrict = 'E';
directive.template = "<div><button>Like</button></div>;
directive.link = function($scope, element) {
$scope.loadTaskList = function() {
$http.get(domain + "/_api/web/lists/getbytitle('stuff')/items?", {
headers: {
"Accept": "application/json; odata=verbose"
}
}).then(function(resp) {
if (resp.data.d.results.length > 0) {
});
console.log(resp.data.d.results);
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<div ng-app="formApp">
<task></task>
</div>
答案 0 :(得分:0)
您的指令中有大量语法和逻辑错误。
domain
变量。formApp
变量。});
。只需修复所有语法错误,就会出现按钮。无法帮助您解决域变量问题。我不知道应该是什么。
var formApp = angular.module('formApp', []);
formApp.directive('task', function($http) {
var directive = {};
directive.restrict = 'E';
directive.template = '<div><button ng-click="loadTaskList()">Like</button></div>';
directive.link = function($scope, element) {
$scope.loadTaskList = function() {
$http.get(domain + "/_api/web/lists/getbytitle('stuff')/items?", {
headers: {
"Accept": "application/json; odata=verbose"
}
}).then(function(resp) {
if (resp.data.d.results.length > 0) {
console.log(resp.data.d.results);
}
});
};
};
return directive;
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<div ng-app="formApp">
<task></task>
</div>
&#13;