小编Ant*_*ère的帖子

无法绑定到'ngModel',因为它不是'input'的已知属性

启动Angular应用程序时出现以下错误,即使未显示该组件也是如此.

我必须注释掉,以便我的应用程序正常运行.

    zone.js:461 Unhandled Promise rejection: Template parse errors:
    Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
        <div>
            <label>Created:</label>
            <input  type="text" [ERROR ->][(ngModel)]="test" placeholder="foo" />
        </div>
    </div>"): InterventionDetails@4:28 ; Zone: <root> ; Task: Promise.then ; Value: 
Run Code Online (Sandbox Code Playgroud)

我正在看着英雄的掠夺者,但我没有看到任何区别.

这是组件文件:

    import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
    import { Intervention } from '../../model/intervention';

    @Component({
        selector: 'intervention-details',
        templateUrl: 'app/intervention/details/intervention.details.html',
        styleUrls: ['app/intervention/details/intervention.details.css']
    })

    export class InterventionDetails
    {
        @Input() intervention: Intervention;

        public test : string = "toto"; …
Run Code Online (Sandbox Code Playgroud)

javascript input typescript angular

1173
推荐指数
39
解决办法
70万
查看次数

如何管理Angular2"表达式在检查后发生了变化"当组件属性依赖于当前日期时间时出现异常

我的组件具有依赖于当前日期时间的样式.在我的组件中,我有以下功能.

  private fontColor( dto : Dto ) : string {
    // date d'exécution du dto
    let dtoDate : Date = new Date( dto.LastExecution );

    (...)

    let color =  "hsl( " + hue + ", 80%, " + (maxLigness - lightnessAmp) + "%)";

    return color;
  }
Run Code Online (Sandbox Code Playgroud)

lightnessAmp是从当前日期时间计算的.如果dtoDate是在过去24小时内,颜色会发生变化.

确切的错误如下:

检查后表情发生了变化.先前价值:'hsl(123,80%,49%)'.当前价值:'hsl(123,80%,48%)'

我知道只有在检查值时才会在开发模式中出现异常.如果选中的值与更新的值不同,则抛出异常.

所以我尝试在以下钩子方法中更新每个生命周期的当前日期时间以防止异常:

  ngAfterViewChecked()
  {
    console.log( "! changement de la date du composant !" );
    this.dateNow = new Date();
  }
Run Code Online (Sandbox Code Playgroud)

......但没有成功.

time components styles typescript angular

135
推荐指数
7
解决办法
12万
查看次数

打字稿:如何循环显示枚举值以便在单选按钮中显示?

在Typescript中循环枚举枚举的正确方法是什么?(目前使用的是typescrip 1.8.1)

我有以下枚举:

export enum MotifIntervention {
    Intrusion,
    Identification,
    AbsenceTest,
    Autre
}

export class InterventionDetails implements  OnInit
{
constructor( private interService: InterventionService )
{
    let i:number = 0;
    for (let motif in MotifIntervention) {
        console.log( motif );
    }
}
Run Code Online (Sandbox Code Playgroud)

显示的结果是一个列表

0
1
2
3
Intrusion,
Identification,
AbsenceTest,
Autre
Run Code Online (Sandbox Code Playgroud)

我确实只想在循环中进行4次迭代,因为枚举中只有4个元素,我不希望0 1 2和3看起来像是枚举的索引号.

javascript arrays enums element typescript

134
推荐指数
1
解决办法
12万
查看次数

Angular2日期管道在IE 11和edge 13/14中不起作用

我正在使用Angular 2.0 final,当我在格式字符串中添加小时和分钟时,我的日期格式不正确:

在组件的模板中,我有:

<th id="lastexecution">{{dto.LastExecution | date:'yyyy-MM-dd HH:mm:ss'}}</th>
Run Code Online (Sandbox Code Playgroud)

IE 11中的输出日期是:

2016-09-27 15:00:9/27/2016 3:53:46 PM:9/27/2016 3:53:46 PM
Run Code Online (Sandbox Code Playgroud)

使用{{dto.LastExecution | 日期: 'YYYY-MM-DD'}}

IE 11中的输出日期是正确的:

2016-09-27
Run Code Online (Sandbox Code Playgroud)

这是我在package.json中使用的组件版本:

{
  "name": "ima_sentinel",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "docker-build": "docker build -t ima_sentinel .",
    "docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ima_sentinel",
    "pree2e": "npm run webdriver:update",
    "e2e": "tsc && concurrently \"http-server -s\" …
Run Code Online (Sandbox Code Playgroud)

format datetime pipe internet-explorer-11 angular

42
推荐指数
4
解决办法
3万
查看次数

Angular:如何暂时突出刚改变的dom元素?

在我自己实现解决方案之前,我想知道在数据绑定属性值刚刚更改时是否有一种简单的方式来更改元素的样式(简短的突出显示).

我的DOM中有很多元素,所以我不想在组件中存储和维护专用属性.

我要强调的元素是传统的输入形式元素:

    <tr field label="Lieu dépôt">
        <select class="cellinput" #lieuDepotBon [(ngModel)]="rapport.LieuDepotBon" (ngModelChange)="changeRapport({LieuDepotBon:$event})">
            <option [ngValue]="null"></option>
            <option [ngValue]="i" *ngFor="let depotBonChoice of DepotBonInterventionValues; let i = index">{{DepotBonIntervention[i]}}</option>
        </select>
    </tr>
    <tr field *ngIf="rapport.LieuDepotBon==DepotBonIntervention.Autre" label="Autre lieu">
        <input class="cellinput" #autreLieuDepotBon [(ngModel)]="rapport.AutreLieuDepotBon" (ngModelChange)="changeRapport({AutreLieuDepotBon:autreLieuDepotBon.value})" />
    </tr>
Run Code Online (Sandbox Code Playgroud)

我听说过Angular2在元素上使用ngModel指令设置的特殊类样式可以帮助我做我需要但我找不到更多关于它的内容.

css typescript angular controlvalueaccessor

19
推荐指数
2
解决办法
3164
查看次数

如何解析从文件加载的soap消息?

我需要解析从磁盘加载的SOAP消息到生成的代理的类型.WCF在从http服务器接收消息时执行此操作,因此我应该可以从磁盘执行此操作.

我使用WCF使用Web服务,我从远程WSDL生成代理客户端.

这是我从网络收到的XML结构(它是用System.ServiceModel.MessageLogging记录的),我想解析生成的类CRResponse:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:PourtuIntf" xmlns:ns2="ns2:PourtuIntf-IPourtu">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <ns2:GetCRResponse>
         <return>
            <ResultCode>0</ResultCode>
            <CR>
               <Theme SOAP-ENC:arrayType="ns1:ItemType[5]">
                  <item>
                     <Key/>
                     <Section SOAP-ENC:arrayType="ns1:Section[3]">
...
Run Code Online (Sandbox Code Playgroud)

当我调用Web服务的'GetCR'操作时,消息被正确转换为WCF生成的代理客户端类型GetCRResponse,但我不知道WCF是如何工作的,我需要从磁盘解析文件.

我试图以这种方式解析消息:

  GetCRResponse body;
  using (var xmlReader =  XmlReader.Create("Requests\\CR.xml"))
  {
      Message m = Message.CreateMessage(xmlReader, int.MaxValue, MessageVersion.Soap11);
      body = m.GetBody<GetCRResponse>();
  }
Run Code Online (Sandbox Code Playgroud)

在GeyBody方法中引发了这个异常:

Expected element 'ActGetCRResponse' from namespace 'http://schemas.datacontract.org/2004/07/Pourtu.PourtuClient'.. Detecting 'Element' with name 'ActGetCRResponse', namespace 'urn:PourtuIntf-IPourtu'.

我尝试使用SoapFormatter:

using ( FileStream fs = new FileStream("Requests\\CR.xml", FileMode.Open) )
{
    SoapFormatter formatter = new SoapFormatter();
    body = (ActGetCRResponse)formatter.Deserialize(fs);
}
Run Code Online (Sandbox Code Playgroud)

.. …

c# xml wcf soap web-services

16
推荐指数
1
解决办法
805
查看次数

ASP.Net Core 2错误处理:如何在Http Response中返回格式化的异常详细信息?

我正在寻找一种方法来返回调用我的Web API方法时发生的任何异常的详细信息.

默认情况下,在生产环境中,错误500"内部服务器错误"是API返回的唯一信息.

它是一个私有API,不通过Internet发布,调用者应用程序需要获取并存储所有细节以防异常.

异常详细信息可以是HttpResponse内容中的JSON格式,允许调用者读取Message属性,以及异常的StackTraceString属性(无HTTP页面,如UseDeveloperExceptionPage配置).

目前默认的启动配置方法是:

public class Startup
{   
    [...]

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
    {
        loggerFactory.AddNLog();
        env.ConfigureNLog(Path.Combine(AppContext.BaseDirectory, "nlog.config"));

        if ( env.IsDevelopment() )
            app.UseDeveloperExceptionPage();
        else
            app.UseStatusCodePages();

        app.UseMvc();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# error-handling asp.net-core asp.net-core-2.0

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

如何将 appsettings.json 文件添加到我的 Azure Function 3.0 配置?

新的 Azure Function 3.0 SDK 提供了一种实现 Startup 类的方法。它允许访问依赖注入可用的服务集合,我可以在其中添加自己的组件和第三方服务。

但我不知道如何使用配置文件。

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
...
Run Code Online (Sandbox Code Playgroud)

我的第三方服务以大型结构为参数,这些配置文件与二进制文件一起复制。我可以将它们复制到appsettings.json文件的一个小节中:

{
  "MachineLearningConfig" : {
     ( about 50+ parameters and subsections )
  }
}
Run Code Online (Sandbox Code Playgroud)

根据部署环境更新配置值。为此,我使用 Azure Devops 的文件转换任务:生产值不同于 staging 和 dev 值。

鉴于文档https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection加载这些选项的方法是:

builder.Services.AddOptions<MachineLearningConfig>()
                .Configure<IConfiguration>((settings, configuration) =>
                                           {
                                                configuration.GetSection("MachineLearningConfig").Bind(settings);
                                           });
Run Code Online (Sandbox Code Playgroud)

但这需要将所有设置添加为主机环境中的键/值字符串,这是我不想做的。它们太多了,不像在 json 配置文件中那样容易维护。

我将appsettings.jsonhost.json一起复制。

但是Azure Function SDK 在启动时读取的appsettings.json文件不是我的应用程序的 appsettings.json,而是 Azure Function …

c# configuration dependency-injection azure azure-functions

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

Angular 2:如何从枚举创建单选按钮并添加双向绑定?

我正在尝试使用Angular2语法从枚举定义创建单选按钮,并将值绑定到具有该枚举类型的属性.

我的HTML包含:

<div class="from_elem">
    <label>Motif</label><br>
    <div  *ngFor="let choice of motifChoices">
        <input type="radio" name="motif" [(ngModel)]="choice.value"/>{{choice.motif}}<br>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

在我的@Component中,我声明了一组选择和值:

private motifChoices: any[] = [];
Run Code Online (Sandbox Code Playgroud)

在@Component的构造函数中,我按以下方式填充选项:

constructor( private interService: InterventionService )
{
    this.motifChoices =
        Object.keys(MotifIntervention).filter( key => isNaN( Number( key )))
            .map( key => { return { motif: key, value: false } });
}
Run Code Online (Sandbox Code Playgroud)

单选按钮显示正确,现在我试图将选定的值绑定到属性.但是,当我单击其中一个按钮时,值choice.value将设置为undefined.

binding button radio two-way angular

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

如何根据 ComosDb 中聚合函数的结果对查询结果进行排序?

我使用 Cosmos Db,需要按COUNT的结果对结果进行排序。

我更喜欢直接在 Cosmosdb 查询的输出中对结果进行排序,而不是每次自己对结果进行排序(或为其创建服务)。

在 Azure 的文档资源管理器中,我对 AggregateEvent 集合执行以下请求:

SELECT * FROM (
    SELECT COUNT(1) AS AlarmCount, a.AlarmType FROM AggregatedEvent a
    WHERE a.AlarmType != null and a.Prom > 0
    GROUP BY a.AlarmType ) AS g
ORDER BY g.AlarmCount
Run Code Online (Sandbox Code Playgroud)

结果出现以下错误消息:

无法解析标识符“AlarmCount”。

如果我使用另一个属性来排序 g.AlarmType(文档中存在的属性),则执行排序。

仅当您有办法使用 CosmosDb 归档订单时,请添加答案。

sql sql-order-by aggregate-functions azure azure-cosmosdb

11
推荐指数
1
解决办法
4469
查看次数