代码之家  ›  专栏  ›  技术社区  ›  Malik Mahsam Awan

从webapi获取角度4中的日期

  •  0
  • Malik Mahsam Awan  · 技术社区  · 8 年前

    仅从WebApi获取Angular 4中的日期

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

    typescript类:

    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;
    
    }
    

    发布日期框

    a

    1 回复  |  直到 8 年前
        1
  •  1
  •   bhaumik shah    8 年前

    你能解释一下你到底想要什么吗?根据我的理解,我给你以下的解决方案

    也许这个代码可以帮助你

     <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" />
    
    推荐文章