如果我理解正确,您希望单击客户端(角度应用程序)以在服务器端调用批处理文件。您可以根据您的要求以多种方式执行此操作,但基本上您希望客户端向服务器发送 http 请求(使用 ajax 调用或表单提交)并在将调用批处理文件的服务器上处理它.
客户端
在客户端,您需要有一个使用角度 ng-click 指令的按钮:
<button ng-click="batchfile()">Click me!</button>
在您的角度控制器中,您需要使用$http service 在某个特定网址上向您的服务器发出 HTTP GET 请求。该网址是什么取决于您如何设置您的快速应用程序。像这样的:
function MyCtrl($scope, $http) {
// $http is injected by angular's IOC implementation
// other functions and controller stuff is here...
// this is called when button is clicked
$scope.batchfile = function() {
$http.get('/performbatch').success(function() {
// url was called successfully, do something
// maybe indicate in the UI that the batch file is
// executed...
});
}
}
您可以使用例如验证此 HTTP GET 请求是否发出。您浏览器的开发工具,例如 Google Chrome's network tab 或 http 数据包嗅探器,例如 fiddler。
服务器端
编辑:我错误地认为 angular-seed 使用的是 expressjs,但事实并非如此。见basti1302's answer on how to set it up server-side "vanilla style" node.js。如果您使用的是 express,您可以在下面继续。
在服务器端,您需要set up the url in your express app 来执行批处理文件调用。由于我们让上面的客户端向/performbatch 发出一个简单的 HTTP GET 请求,我们将这样设置它:
app.get('/performbatch', function(req, res){
// is called when /performbatch is requested from any client
// ... call the function that executes the batch file from your node app
});
调用批处理文件以某些方式完成,但您可以在此处阅读 stackoverflow 答案以获得解决方案:
希望对你有帮助