Angular 环境变量
我有两个html页面index.html和login.html页面。angular应用程序使用index.html页面,是否有方法在login.html页面中注入或访问环境值 我不想重复环境设置两次,因为它们可能会不同步 编辑 下面是登录页面标记。在下面的代码中,我需要更改权限,根据运行它的环境重定向uri。运行angular的Index.html页面使用environment.ts文件存储特定于环境的URL,并在构建时使用这些设置编译项目。我遇到的问题是无法访问外部的environment.ts变量Angular 环境变量,angular,angular-cli,Angular,Angular Cli,我有两个html页面index.html和login.html页面。angular应用程序使用index.html页面,是否有方法在login.html页面中注入或访问环境值 我不想重复环境设置两次,因为它们可能会不同步 编辑 下面是登录页面标记。在下面的代码中,我需要更改权限,根据运行它的环境重定向uri。运行angular的Index.html页面使用environment.ts文件存储特定于环境的URL,并在构建时使用这些设置编译项目。我遇到的问题是无法访问外部的environment.t
<head>
<script src="assets/scripts/oidc-client.min.js"></script>
<script type="text/javascript">
function onUserLoggedOut(arg) {
const settings = {
authority: 'http://localhost:2228',
client_id: '#####',
redirect_uri: 'http://localhost:4200/auth.html',
post_logout_redirect_uri: 'http://localhost:4200',
response_type: 'id_token token',
scope: 'openid',
monitorSession: true,
silent_redirect_uri: 'http://localhost:4200/silent-renew.html',
automaticSilentRenew: false,
silentRequestTimeout: 30000,
accessTokenExpiringNotificationTime: 30,
filterProtocolClaims: true,
loadUserInfo: true,
acr_values: 'tenant:1'
};
(new Oidc.UserManager(settings)).signinRedirect(tenant_acr).then((resp) => {
});
}
</script>
</head>
<body>
<iframe src="http://localhost:2228/Account/Logout" onload="onUserLoggedOut(this)" >
</iframe>
</body>
函数onUserLoggedOut(arg){
常量设置={
当局:'http://localhost:2228',
客户id:'客户id',
重定向_uri:'http://localhost:4200/auth.html',
post\u注销\u重定向\u uri:'http://localhost:4200',
响应类型:“id\U令牌”,
作用域:“openid”,
监视器会话:正确,
静默\u重定向\u uri:'http://localhost:4200/silent-更新.html',
automaticSilentRenew:错误,
silentRequestTimeout:30000,
accessTokenExpiringNotificationTime:30,
filterProtocolClaims:对,
loadUserInfo:true,
acr_值:“租户:1”
};
(新的Oidc.UserManager(设置)).SignInDirect(租户\u acr)。然后((响应)=>{
});
}
Angular应用程序是否同时提供这两个页面?环境变量是通过命令行传递到应用程序中的,还是已经在Angular应用程序中(在组件等中)只有索引页由Angular提供服务。我正在使用angular cli环境文件存储不同环境的设置。使用angular DI将环境对象注入到组件中。您能否发布更多关于您的设置以及如何提供login.html
的信息?最好只将其存储在后端的某个位置或作为构建过程的一部分,但这取决于您的设置。@joh04667我已按问题编辑过。正如您所提到的,我可能需要编写一些节点任务来在构建时在非角度html页面中替换环境变量。好的。如果它在后端,您可以在启动时作为Angular的APP\u初始值设定程序的一部分获取该数据。有关更多详细信息,请参阅本文: