1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > angular6 设置全局变量_angular6 – 如何在index.html中为Angular 6使用环境变量

angular6 设置全局变量_angular6 – 如何在index.html中为Angular 6使用环境变量

时间:2021-01-07 07:50:06

相关推荐

angular6 设置全局变量_angular6 – 如何在index.html中为Angular 6使用环境变量

将您的环境文件导入.ts文件.

import { environment } from '../../environments/environment';

在类中创建必需的字段,在构造函数中将环境中的值分配给这些变量,在.html文件中使用通常的绑定.

.TS

import { Component } from '@angular/core';

import { environment } from '../environments/environment';

@Component({

selector: 'app-root',

templateUrl: './ponent.html',

styleUrls: ['./ponent.css']

})

export class AppComponent {

public production = true;

constructor() {

this.production = environment.production;

}

}

html的

{{production}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。