这个我的js文件我不知道为什么它不起作用,我想从js文件执行cordova cmd:当我点击按钮时项目将被创建:
(function(angular) {
'use strict';
var myApp = angular.module("myApp", []);
myApp.factory("items", function() {
var items = {};
items.data = [];
return items;
});
myApp.controller("createController", function createController($scope, items) {
$scope.items = items;
$scope.deleteItem = function(index) {
items.data.splice(index, 1);
}
$scope.addItem = function(index) {
items.data.push({
id: $scope.items.data.length + 1,
title: $scope.newName
});
$scope.newItemName=""
$scope.idname=""
var name=$scope.newName;
var id=$scope.idname;
var fs = require('fs');
var path = require('path');
var sys = require('sys');
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
sys.puts(stdout);
}
exec("cordova create"+name+id, puts);
}
});
})(angular)
答案 0 :(得分:0)
Angular 1.x无法运行后端(与Node一样),只有在实际html页面的实际浏览器中运行时才有效。使用Angular运行单个js文件没有意义。
即。你需要创建一个index.html,在head或body中包含你的angular.js文件(来自cdn或本地),然后包含你的test.js.请注意,由于测试取决于Angular,因此必须首先包含Angular。然后,只需打开index.html