【问题标题】:Date get in angular 4 from webapi从 webapi 获取角度 4 的日期
【发布时间】:2018-05-09 20:33:28
【问题描述】:

仅日期从 WebApi 获取 Angular 4

publish Date Get from webApi <br>
<PublishDate>2018-03-02T00:00:00</PublishDate><br>

打字稿类:

export class IResource {
    ResourceId: number;
    ResourceTitle: string;
    Description: string;
    PublishDate?: Date;
    ImgUrl: string;  
}

服务:

GetResourceById(resourceId) {
    this.appServiceManager.libGet("Resource/" + resourceId).
        subscribe((response: any) => {
            this.resource = response;            
           }

        }, (error: any) => {
            alert(error);
        });
}

HTML 文件:

 <div class="col-md-4 noPadding">Publish Date</div>
   <div class="col-md-8 noPadding">
      <p-calendar name="PublishDate" [(ngModel)]="resource.PublishDate" 
          dateFormat="mm/dd/yy" [showIcon]="true"></p-calendar>
   </div>

获取发布日期的 API 服务

public ResourceDTO Find(int id)
{
    //get resource get by id
    Resource dbresource = _db.Resources.Where(m => m.ResourceId == id).FirstOrDefault();
    ResourceDTO resourcesDTO = Mapper.Map<ResourceDTO>(dbresource);[enter image description here][1]

    return resourcesDTO;

}

发布日期框

【问题讨论】:

  • 你知道有角的管道吗?
  • 我的问题通过日期管道解决了

标签: date sql-server-2012 asp.net-web-api2 angular4-forms


【解决方案1】:

你能解释一下你到底想要什么,我给你的解决方案作为我的理解

也许这段代码会对你有所帮助

 <input type="date" class="form-control" max="{{todaysDate|date:'yyyy-MM-dd'}}" #myDate [value]="your model | date:'yyyy-MM-dd'"
                                           (input)="your model=$event.target.value" />

【讨论】:

  • api 获取日期时间,但我只想显示日期(2018-04-28 16:57:18.257)
猜你喜欢
  • 1970-01-01
  • 2019-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多