Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在每次单击时进行API调用_Angularjs_Node.js - Fatal编程技术网

Angularjs 在每次单击时进行API调用

Angularjs 在每次单击时进行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

我是网络开发新手,似乎在任何地方都找不到这个问题的答案。我希望我的nodejsapi端点在每次ng单击时都被调用,而不仅仅是在页面加载时。以下是我到目前为止的情况:

HTML:

NodeJS

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;
      });
    }
});