小编Vin*_*nce的帖子

将参数传递给 EF Core 的 IDesignTimeDbContextFactory

我们如何将参数传递给 dotnet ef 数据库更新?

我希望能够使用参数更新不同的数据库。

我试过了

dotnet ef 数据库更新“接受”

dotnet ef 数据库更新 接受

但它没有用..

或者我如何放置一个开关以从我的配置中获取不同的 conenctionString ?

public ProjectContext CreateDbContext(string[] args)
{
    IConfigurationRoot configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json")
        .Build();

    // Find a way to get different connection string 
    var connectionString = configuration.GetConnectionString(args[0]);

    var builder = new DbContextOptionsBuilder<ProjectContext >();
    builder.UseSqlServer(connectionString);

    return new ProjectContext(builder.Options);
}
Run Code Online (Sandbox Code Playgroud)

entity-framework-core .net-core

9
推荐指数
1
解决办法
2947
查看次数

如何重置控制值?

我正在尝试控制我们可以输入带有标签和分数的多个玩家.

但是当我们单击我的AddPlayer按钮时,我创建了一个播放器,然后我需要将表单控件值重置为默认值.

我已经尝试了很多东西,但没有任何作用....它永远不会改变视图值.

这是代码:

addPlayer(form: ControlGroup) {
    var player = new Player();
    player.tag = form.value.tag;
    player.name = form.value.name;
    player.score = form.value.score;

    // nothing work
    form.value = null;
    form.value.tag = null;
    form.value.tag = '';

    this.playerService.addPlayer(player.tag, player.name, player.score);
    this.newplayer.next(player);
}
Run Code Online (Sandbox Code Playgroud)

这是html

<form (submit)="addPlayer(playerForm)" [ng-form-model]="playerForm">
    <div class="form-group" [class.has-error]="!playerForm.find('tag').valid && playerForm.find('tag').touched">
        <div class="col-md-3 text-right">
            <label for="tag">Tag: </label>
        </div>

        <input type="text" id="tag" #tag="form" [ng-form-control]="playerForm.controls['tag']"  placeholder="Tag"/>

        <span *ng-if="tag.control.hasError('required') && !tag.control.pristine">Tag is required</span>
    </div>

    <div class="form-group" [class.has-error]="!playerForm.find('name').valid && playerForm.find('name').touched">
        <div class="col-md-3 text-right">
            <label for="name">Player Name: </label>
        </div> …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
7552
查看次数

Angular2 重定向路由不会更改浏览器 url

试图在我的 angular2 应用程序中创建我的重定向路由。

但我的问题是,当有人输入像“nopath”这样的无效路径时,用户会被重定向到“HomeComponent”,但 url 仍然保留“/#/nopath”

我也希望 redirectTo 路由更改 url!我应该如何实现这一目标?

我应该在我的 HomeComponent 构造函数中放置一个 if 来检查当前 url 并将他的路由更改为 homecomponent 吗?还是我遗漏了什么?

路线:

const routes: Routes = [
  { path: '', pathMatch: 'full', component: HomeComponent },
  { path: 'login', component: LoginComponent, canActivate: [AnonymousGuard] },
  { path: 'register', component: RegisterComponent, canActivate: [AnonymousGuard] },
  { path: 'users', component: UserComponent, canActivate: [AuthGuard] },
  { path: '**', redirectTo: '' }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {useHash: true});
Run Code Online (Sandbox Code Playgroud)

编辑:

试过了,但我没有重定向到 home 组件

const routes: Routes = …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

5
推荐指数
0
解决办法
8039
查看次数

Angular5自定义验证器的日期最小值

我正在尝试为日期输入创建一个验证器。

所以我已经写了这段代码,但是没有按预期工作!

export class CustomValidators {
  static dateMinimum(date: string): ValidatorFn {
    return (control: AbstractControl): ValidationErrors | null => {
      if (control.value == null) {
        return null;
      }

      const controlDate = moment(control.value, FORMAT_DATE);

      if (!controlDate.isValid()) {
        return null;
      }

      const validationDate = moment(date);

      return controlDate.isAfter(validationDate) ? null : {
        'date-minimum': {
          'date-minimum': validationDate.format(FORMAT_DATE),
          'actual': controlDate.format(FORMAT_DATE)
        }
      };
    };
  }
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

ERROR Error: Expected validator to return Promise or Observable.at toObservable (forms.js:749)
Run Code Online (Sandbox Code Playgroud)

我真的不知道哪件事是不正确的...我发现了很多示例,这些示例如何创建不带参数但不带参数的自定义验证器...

我需要像这样使用验证器:

    this.projectForm = this.builder.group({
      date: ['', Validators.required, CustomValidators.dateMinimum('2018-12-12')], …
Run Code Online (Sandbox Code Playgroud)

angular-validation angular

5
推荐指数
1
解决办法
4354
查看次数

angular 5, RxJs { map } 导入不起作用或者我遗漏了什么?

我正在尝试映射 httpclient 的结果,我们需要使用 RxJs 的新导入来使 treeshaking 工作。

所以我找到了 2 张地图,但都没有用...

import { map } from 'rxjs/operator/map'; 
import { map } from 'rxjs/operators/map';
Run Code Online (Sandbox Code Playgroud)

我们需要删除的旧时尚方式

import 'rxjs/add/operator/map';
Run Code Online (Sandbox Code Playgroud)

这是我开始工作所需的代码!

  getValues(): Observable<Value[]> {   
    return this.http.get<Response<Values>>(this.url).map(reponse => {
      return reponse.data.values;
    });
  }
Run Code Online (Sandbox Code Playgroud)

但 .map 并不以可观察性而闻名,

rxjs5 angular angular5

3
推荐指数
1
解决办法
8602
查看次数

在JS中将刻度转换为日期

我正在尝试检查JWT令牌的到期日期,而我尝试执行的所有操作均未获得正确的日期。

"exp": 1522210228 => real answer => Wednesday, March 28, 2018 12:10:28 AM
Run Code Online (Sandbox Code Playgroud)

我尝试过那些libs,但没有使它们起作用...

  1. https://github.com/auth0/angular2-jwt/blob/master/src/jwthelper.service.ts
  2. https://github.com/auth0/jwt-decode

1个

const helper = new JwtHelperService();
const decodedToken = helper.decodeToken(this.authentificationInfos.token);
const expirationDate = helper.getTokenExpirationDate(this.authentificationInfos.token);

console.log(expirationDate); => null?
Run Code Online (Sandbox Code Playgroud)

2

import * as decode from 'jwt-decode';

const token = decode<{ data: { exp: number, iat: number, iss: string, nbf: number, username: string } }>(this.authentificationInfos.token);
const date = new Date(token.data.exp);
console.log(date); => Sun Jan 18 1970 09:50:10 GMT-0500 (Eastern Standard Time)

const d = new Date(0);
d.setUTCMilliseconds(token.data.exp); …
Run Code Online (Sandbox Code Playgroud)

javascript jwt typescript

3
推荐指数
3
解决办法
3253
查看次数

使用 Github Repo 的 Azure/DevOps - 要构建的项目的路径

我正在尝试在 VSTS(Azure DevOps)到 Azure WebApp 的帮助下为 Github 上的项目创建 CI/CD 管道。

我正处于该过程的开始阶段,并且一直坚持让我的项目直接在 VSTS 中构建。

后端项目为DotNetCore项目,前端尚未确定。

我在 github 上的存储库看起来像这样

/
 -> Project.FrondEnd
 -> Project.BackEnd
 -> Documents
 -> .gitignore
 -> readme.md
Run Code Online (Sandbox Code Playgroud)

在文件夹 Project.BackEnd 中,它将如下所示:

/Project.BackEnd
 -> Project.Api (Entry point of the server app)
 -> Project.Entities
 -> Project.DataAccess
 -> Project.Services
 -> Project.sln
Run Code Online (Sandbox Code Playgroud)

当我在 VSTS 上配置管道时,我需要编写 pipeline.yml 文件,但似乎我缺少一些关于如何指向我的服务器入口点以便它可以构建项目的知识!

这是我的 yml 文件

trigger:
- master

pool:
  vmImage: 'vs2017-win2016'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)

这样它就行不通了,我收到了这条消息:

错误 MSB1003:指定项目或解决方案文件。当前工作目录不包含项目或解决方案文件。

我试图将步骤更改为这样的 …

azure-devops azure-pipelines

2
推荐指数
1
解决办法
2540
查看次数