【问题标题】:Implement PHP's static array in angular 2在angular 2中实现PHP的静态数组
【发布时间】:2017-10-29 15:57:11
【问题描述】:

我想在 Angular 2 中实现一个静态数组,与 PHP 中的这个数组等效。我该怎么做?

 <?php
 class Services
 {
     const TaskPoll         =   "TaskPoll";
     const ModuleList       =   "ModuleList";

     public static $services = array
     (
        Services::TaskPoll              =>array("APIURL"=>"task/poll","APIRequestType"=>"PostAPI","RestService"=>["WarName"=>"abc","ServiceUrl"=>"http://localhost:8080"]),
        Services::ModuleList            =>array("APIURL"=>"task/modulelist","APIRequestType"=>"GetAPI","RestService"=>["WarName"=>"abc","ServiceUrl"=>"http://localhost:8080"]),
     );
 }

【问题讨论】:

  • 为什么要在PHPAngualr 2 中编写代码?我的意思是上面的代码
  • @Mr_Perfect 我需要在 Angular 2 中移植相同的代码。这就是原因

标签: php arrays angular static constants


【解决方案1】:
class Services {
  public static readonly TaskPoll = 'TaskPoll';
  public static readonly ModuleList = 'ModuleList';

  public static readonly $services = {
    TaskPoll: {'APIURL': 'task/poll', 'APIRequestType': 'PostAPI', 'RestService': {'WarName': 'abc', 'ServiceUrl': 'http://localhost:8080'}},
    ModuleList: {'APIURL': 'task/modulelist', 'APIRequestType': 'GetAPI', 'RestService': {'WarName': 'abc', 'ServiceUrl': 'http://localhost:8080'}}
  };
}

console.log(Services.$services.TaskPoll);

【讨论】:

    猜你喜欢
    • 2013-10-23
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2017-10-12
    • 2023-04-04
    相关资源
    最近更新 更多