How to make a string constant in angular 4?

后端 未结 3 1798
萌比男神i
萌比男神i 2021-02-05 11:03

In my service, I am using a http post. I want to set the URL as a constant.

return this.http.get(this.config.API_URL+\'users\', options).map(res=&g         


        
3条回答
  •  离开以前
    2021-02-05 11:54

    I'm not sure if i understand your question but if you want to create constants, you can do it in a different class and import it.

    constants.ts

    export class Constants {
      public static get HOME_URL(): string { return "sample/url/"; };
    }
    

    sample.component.ts

       import { Constants } from "./constants";
        @Component({
    
        })
         export class SampleComponent {
          constructor() {
           let url = Constants.HOME_URL;
          }
        }
    

提交回复
热议问题