Php Angular.js>;如何管理配置

Php Angular.js>;如何管理配置,php,angularjs,Php,Angularjs,我一直在向angular应用程序传递配置。我的问题是 我们已经将配置存储在数据库中,到目前为止,它是web服务的URL,可以与之通信 页面由PHP呈现 如何将存储在数据库中的URL传递给ng应用程序 到目前为止,我有硬编码的services.js app.constant('config', {ws_url: 'ws://domain/ws'}); app.factory('wampy', function ($rootScope, config) { var url = config

我一直在向angular应用程序传递配置。我的问题是

  • 我们已经将配置存储在数据库中,到目前为止,它是web服务的URL,可以与之通信
  • 页面由PHP呈现
  • 如何将存储在数据库中的URL传递给ng应用程序

    到目前为止,我有硬编码的services.js

    app.constant('config', {ws_url: 'ws://domain/ws'});
    
    app.factory('wampy', function ($rootScope, config) {
    
      var url =  config.ws_url;
      var ws = new Wampy(url, { autoReconnect: true });
    
      return {
        something: function () {
            console.log(url);   // usage of url
        }
      }
    
    }
    
    然后它被包含在主html代码(index.php)中

    
    
    但是它可以被修改/移动到其他地方


    有什么想法吗?

    您可以将一段javascript由php呈现到脚本标记中,如下所示

    $config = array('ws_url' => 'ws://domain/ws');
    $jsonConfig = json_encode($config);
    
    $snippet = <<<EOS
        <script type="text/javascript">
            angular.module('appName').constant('config', $jsonConfig);
        </script>
    EOS;
    
    $config=array('ws_url'=>'ws://domain/ws');
    $jsonConfig=json_encode($config);
    $snippet=
    
    $config = array('ws_url' => 'ws://domain/ws');
    $jsonConfig = json_encode($config);
    
    $snippet = <<<EOS
        <script type="text/javascript">
            angular.module('appName').constant('config', $jsonConfig);
        </script>
    EOS;