Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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 使用节点启动应用程序时传入角度变量_Angularjs_Node.js_Gruntjs - Fatal编程技术网

Angularjs 使用节点启动应用程序时传入角度变量

Angularjs 使用节点启动应用程序时传入角度变量,angularjs,node.js,gruntjs,Angularjs,Node.js,Gruntjs,我在angular.js中的客户端app.js上有此设置: var options = {}; options.api = {}; options.api.base_url = "http://myDomainName.tld:8080"; 在构建应用程序时,我需要能够在CLI上更改此设置 我的想法是和格伦特一起做 如何解决这个问题还有其他想法吗?您可以使用该模块 将您的app.js文件添加为app.js.tpl app.js.tpl var options = {}; options.api

我在angular.js中的客户端app.js上有此设置:

var options = {};
options.api = {};
options.api.base_url = "http://myDomainName.tld:8080";
在构建应用程序时,我需要能够在CLI上更改此设置

我的想法是和格伦特一起做

如何解决这个问题还有其他想法吗?

您可以使用该模块

将您的
app.js
文件添加为
app.js.tpl

app.js.tpl

var options = {};
options.api = {};
options.api.base_url = "<%= base_url %>";

投票支持这项努力,但迄今为止没有奏效。你测试了吗?@sirbenji我没有测试它,但没有真正的理由说明它不应该工作。它没有被编译,不管怎样,我找到了另一个解决方案(根本没有将环境变量放入我的客户端/app.js)。然而,你成功地超越了工作吗?你写了“它应该能起到很好的作用……”
module.exports = function(grunt) {
    grunt.initConfig({
        'template': {
            'process-js-template': {
                'options': {
                    'data': {
                        'base_url': 'http://myDomainName.tld:8080'
                        //Can also use 'base_url': grunt.option('base_url')
                        //If you wanted to take it from the CLI.
                        //EG: grunt default --base_url=http://myDomainName.tld:8080
                    }
                },
                'files': {
                    //The key being where you want to save the file.
                    'path/to/app.js': ['path/to/app.js.tpl']
                }
            }
        }
    });
    grunt.loadNpmTasks('grunt-template');
    grunt.registerTask('default', [
        'template'
    ]);
};