我需要读取json格式的配置文件.json文件包含键/对值中的配置条目.如何获取任何特定键的值?
我的问题是,我可以使用http.get()或任何其他方式读取整个json文件,但是如何根据键获取特定的配置值?我应该循环/迭代项目以获得所需的项目还是有其他更好的方法来做到这一点?
我的json配置如下所示
{
"SecurityService": "http://localhost/SecurityAPI",
"CacheService": "http://localhost/CacheServiceAPI"
}
Run Code Online (Sandbox Code Playgroud)
我按照你的建议尝试进行代码更改从json文件中读取配置数据的代码
getConfiguration = (): Observable<Response> => {
return this.http.get('config.json').map(res => res.json());
}
Run Code Online (Sandbox Code Playgroud)
以下代码从调用组件调用上述方法并使用read配置值
this._ConfigurationService.getConfiguration()
.subscribe(
(res) => {
this.configs = res;
console.log(this.configs);
},
(error) => console.log("error : " + error),
() => console.log('Error in GetApplication in Login : ' + Error)
);
Run Code Online (Sandbox Code Playgroud)
但是当上面的内容被执行时,我得到的错误是
"error : SyntaxError: Unexpected token < in JSON at position 0"
我在这里做的错误是什么,读取json文件的相同代码在我需要从json读取数据并绑定网格等的其他场景中有效.
我试过在plunkr中重现这个问题https://plnkr.co/edit/rq9uIxcFJUlxSebO2Ihz?p=preview
我们已将我们的项目从 Asp.Net 核心 RC1 迁移到 RC2。迁移后,我们在以下位置收到 2 个编译错误。
第一个问题是在startup.cs中,“以下方法或属性之间的调用不明确:”
public void ConfigureServices(IServiceCollection services)
{
...
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
...
}
Run Code Online (Sandbox Code Playgroud)
错误详情:
Error CS0121 The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionExtensions.AddIdentity<TUser, TRole>(Microsoft.Extensions.DependencyInjection.IServiceCollection)' and 'Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionExtensions.AddIdentity<TUser, TRole>(Microsoft.Extensions.DependencyInjection.IServiceCollection)' Firebolt.SecurityService..NETCoreApp,Version=v1.0 C:\Krishnan\RSI\SourceCode\Bluesky Developement\BlueSky Development\Firebolt.Security\src\Firebolt.Security\Startup.cs 58 Active
Run Code Online (Sandbox Code Playgroud)
第二期:
[Microsoft.Data.Entity.Infrastructure.DbContext(typeof(ApplicationDbContext))]
[Migration("00000000000000_CreateIdentitySchema")]
partial class CreateIdentitySchema
{
protected override void BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder modelBuilder)
{
...
}
Run Code Online (Sandbox Code Playgroud)
错误详情:
Error CS0115 'CreateIdentitySchema.BuildTargetModel(ModelBuilder)': no suitable method found to override Firebolt.SecurityService..NETCoreApp,Version=v1.0 C:\Krishnan\RSI\SourceCode\Bluesky Developement\BlueSky Development\Firebolt.Security\src\Firebolt.Security\Migrations\00000000000000_CreateIdentitySchema.Designer.cs 15 Active
Run Code Online (Sandbox Code Playgroud)
这两个问题的解决方法是什么?有任何想法吗
我需要将组件以角度动态加载到选项卡中。我有一个父组件,里面有角标签。在选项卡控件中,我需要动态加载子组件。
最初,当标签被加载时,它应该加载一个 component1,并且在一些用户交互中,它应该触发事件,该事件将加载其他标签和其他子组件以加载到其中。
我的要求是在每个选项卡内动态加载任何子组件。
我在选项卡内动态加载子组件时遇到问题,不知道如何进一步处理?
我在stackblitz 中创建了一个用于演示的 POC
我的父组件如下:
import {Component, ViewChild, AfterViewInit, TemplateRef, ComponentRef, ViewContainerRef} from '@angular/core';
import { ComponentFactoryResolver } from '@angular/core';
import { Component1 } from './Component1';
import { Component2 } from './Component2';
@Component({
selector: 'home',
template: `<mat-tab-group class="demo-tab-group">
<mat-tab *ngFor="let tab of homepageTabs; let i = index" label="{{tab.label}}">
<!--Component1 and Component2 to be loaded here... what is the correct container object which can hold dynamic components ? -->
<ng-template #container>{{tab.templateRef}}</ng-template>
</mat-tab>
</mat-tab-group>`
})
export …Run Code Online (Sandbox Code Playgroud) 从Beta-17迁移到RC4后,我遇到的问题很少.我收到以下编译错误
引导错误
/// < reference path="../node_modules/angular2-in-memory-web-api/typings/browser.d.ts" >
import {bootstrap} from '@angular/platform-browser';
Error: Module "../platform-browser/index" as no exported member bootstrap
Run Code Online (Sandbox Code Playgroud)
路由器错误
import {ROUTER_PROVIDERS, RouteConfig, ROUTER_DIRECTIVES, RouteParams, ROUTER_BINDINGS} from '@angular/router';
Error: Cannot find module '@angular/router'
Run Code Online (Sandbox Code Playgroud)
我尝试使用路由器也弃用了,仍然发现模块未找到错误
import {ROUTER_PROVIDERS, RouteConfig, ROUTER_DIRECTIVES, RouteParams, ROUTER_BINDINGS} from '@angular/router-deprecated';
Error: Cannot find module '@angular/router-deprecated'
Run Code Online (Sandbox Code Playgroud)
如果不推荐使用现有路由器,那么实现路由的新方法是什么?
我在以下文档中验证了URL,但没有注意到很多区别.
任何人都可以对此有所了解吗?
根据评论更新:新的错误集
我现在可以导入bootstrap和路由器,但是我收到了一些其他错误
错误#1.无法导入RouteConfig
import { ROUTER_DIRECTIVES, RouterOutlet, RouteConfig } from '@angular/router';
Error: Module "../angular/router/index has no exported member RouteConfig"
Run Code Online (Sandbox Code Playgroud)
为了使路由器不再使用,即我现有的路由实现,我需要导入RouteConfig.我不确定从哪里可以导入RouteConfig
除此之外,我得到了近210个编译错误,如下所示.当我搜索以下错误时,建议添加以下行
/// ../node_modules/angular2/typings/browser.d.ts"/> …
迁移到 Angular 材料 5.2.2 后,我收到以下错误。在此之前,我的应用程序是 Angular 材料 2.0.0-beta.10。
更改 package.json 中的版本并运行 npm install 后,我也按照/sf/answers/3340841801/帖子中提到的步骤操作
我注意到所有Md*标签都更改为Mat*,但现在我面临错误
ERROR in .../src/app/pages/messagebox/messagebox-component.ts (2,10): Module '".../node_modules/@angular/material/material"' has no exported member 'MAT_DIALOG_DATA'.
ERROR in .../src/app/pages/messagebox/messagebox-component.ts (2,27): Module '".../node_modules/@angular/material/material"' has no exported member 'MatDialogRef'.
ERROR in .../src/app/pages/bisstatus/bisjobstatistics.component.ts (12,10): Module '".../node_modules/@angular/material/material"' has no exported member 'MatDialog'.
ERROR in .../src/app/pages/bisstatus/bisjobstatistics.component.ts (21,10): Module '".../node_modules/@angular/material/material"' has no exported member 'MatDialogRef'.
ERROR in .../src/app/pages/bisstatus/bisjoblog.component.ts (12,10): Module '".../node_modules/@angular/material/material"' has no exported member 'MatDialog'.
ERROR in .../src/app/pages/bisstatus/bisjoblog.component.ts (21,10): …Run Code Online (Sandbox Code Playgroud)