Angularjs 在每次单击时进行API调用
我是网络开发新手,似乎在任何地方都找不到这个问题的答案。我希望我的nodejsapi端点在每次ng单击时都被调用,而不仅仅是在页面加载时。以下是我到目前为止的情况: HTML: NodeJSAngularjs 在每次单击时进行API调用,angularjs,node.js,Angularjs,Node.js,我是网络开发新手,似乎在任何地方都找不到这个问题的答案。我希望我的nodejsapi端点在每次ng单击时都被调用,而不仅仅是在页面加载时。以下是我到目前为止的情况: HTML: NodeJS app.get('/test', function(req, res) { console.log("test get"); }); 这就是你要找的吗 HTML: 这就是你要找的吗 HTML: var app = angular.module('myApp', []); app.controlle
app.get('/test', function(req, res) {
console.log("test get");
});
这就是你要找的吗 HTML:
这就是你要找的吗 HTML:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.post("/test").then(function(response) {
$scope.testString = response.data;
});
});
app.get('/test', function(req, res) {
console.log("test get");
});
<button ng-click="myFunction()">Click me!</button>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.myFunction = function() {
$http.post("/test").then(function(response) {
$scope.testString = response.data;
});
}
});