2017-05-22 49 views
1
"@angular/cli": "1.0.0", 
"@angular/compiler": "2.4.9", 
"@angular/compiler-cli": "2.4.9", 
"@angular/core": "2.4.9", 

這是我的第一個中等大小的angular2項目,在嘗試部署到Heroku時出現以下錯誤。提供的參數不匹配呼叫目標的任何簽名。 Heroku部署

ERROR in /tmp/build_517db5365a6effb7ffc72a360964722f/src/$$_gendir/app/modules/messages/components/list-messages.component.ngfactory.ts (440,79): Supplied parameters do not match any signature of call target.

的package.json腳本:

"scripts": { 
    "ng": "ng", 
    "heroku-prebuild": "npm install -g http-server", 
    "heroku-postbuild": "ng build --prod", 
    "start": "http-server dist/", 
    "test": "ng test", 
    "lint": "ng lint", 
    "e2e": "ng e2e" 
    }, 

請注意,此錯誤只嘗試部署到Heroku的,運行時ng build --prod本地,我沒有得到同樣的錯誤,編譯完成時發生沒有錯誤。

我一直在尋找任何缺乏預期參數的函數,但組件太簡單了,我真的沒有看到它。

這裏是我的名單,messages.component.ts:

import { Component } from '@angular/core' 
import { Router } from '@angular/router' 
import { MessagesService } from '../services/messages.service' 


@Component({ 
    templateUrl: 'list-messages.component.html', 
    providers: [ MessagesService ], 
    styleUrls: ['./list-messages.component.css'] 
}) 

export class ListMessagesComponent { 

    public messages: any 
    public search_q: any 
    public errors: string 
    public success: string 
    public page: any 
    private total: number 
    private limit: any 


    constructor(public router: Router, private messageService: MessagesService) {} 

    ngOnInit() { 
     this.page = 0 
     this.limit = 20 
     this.messageService.getMessages(this.page, this.limit) 
      .subscribe(res => { 
       console.log(res) 
       if (res.status == 200 && res.data.length > 0) { 
        this.messages = res.data 
        this.total = res.total 
       } else { 
        this.errors = res.message || "Unable to complete operation" 
       } 
      }) 
    } 

    /** 
    * On search event 
    */ 

    onSearch(query) { 
     this.search_q = query 
    } 

    deleteMessage(id) { 
     if (id) { 
      this.messageService.deleteMessage(id) 
       .subscribe(res => { 
        if (res.status == 200) { 
         this.messageService.getMessages(this.page, this.limit) 
          .subscribe(res => { 
           if (res.status == 200) { 
            this.success = "Message deleted" 
            this.messages = res.data 
            this.total = res.total 
           } else { 
            this.success = null 
            this.errors = res.message || "Unable to get messages" 
           } 
          }) 
        } 
       }) 
     } else { 
      this.success = null 
      this.errors = "Unknown message" 
     } 
    } 


    // -------- PAGINATION ------- // 

    /** 
    * Loads next page 
    * 
    */ 

    nextPage() { 
     this.page += 1 
     this.messageService.getMessages(this.page, this.limit) 
      .subscribe(res => { 
       if (res.status == 200) { 
        this.success = null 
        this.errors = null 
        this.messages = res.data 
        this.total = res.total 
       } 
      }) 
    } 

    /** 
    * Checks if there is a next page 
    */ 

    hasNextPage() { 
     return this.page * this.limit < this.total && this.messages.length == this.limit 
    } 

    /** 
    * Loads previous page 
    * 
    */ 

    prevPage() { 
     if (this.page > 0) { 
      this.page -= 1 
      this.messageService.getMessages(this.page, this.limit) 
       .subscribe(res => { 
        if (res.status == 200) { 
         this.success = null 
         this.errors = null 
         this.messages = res.data 
         this.total = res.total 
        } 
       }) 
     } 
    } 

    /** 
    * Checks if there is a previous page 
    * 
    */ 

    hasPrevPage() { 
     return this.page >= 1 
    } 

} 

,這裏是我的messages.service.ts(以防萬一):

import { Injectable } from '@angular/core' 
import { Http, Headers, RequestOptions, URLSearchParams } from '@angular/http' 
import { Observable } from 'rxjs/Observable' 
import { environment } from '../../../../environments/environment' 
import 'rxjs/add/observable/throw' 
import 'rxjs/add/operator/map' 
import 'rxjs/add/operator/catch' 


@Injectable() 
export class MessagesService { 

    private baseUrl:string 
    private currentUser:any 
    private token:string 
    private headers:Headers 

    constructor(private http: Http){ 
     this.http = http 
     this.baseUrl = environment.api_url 
     this.currentUser = JSON.parse(localStorage.getItem('current-user')) 
     this.token = JSON.parse(localStorage.getItem('auth-token')) 
     this.headers = new Headers() 
     this.headers.append("Accept", "application/json") 
     this.headers.append("Content-Type", "application/json") 
     this.headers.append("x-user-id", this.currentUser._id) 
     this.headers.append("x-access-token", this.token) 
    } 

    /** 
    * Retrieves all messages 
    */ 

    getMessages(page?:string, limit?:string) { 
     let queryParam = new URLSearchParams() 
     queryParam.set('page', page) 
     queryParam.set('limit', limit) 
     let options = new RequestOptions({ headers: this.headers, search: queryParam }) 
     return this.http.get(this.baseUrl + '/messages', options) 
      .map(res => res.json()) 
      .catch(this.errorHandler) 
    } 

    /** 
    * Delete a specific message 
    * @param id 
    */ 

    deleteMessage(id) { 
     this.headers.delete('x-message-id') 
     this.headers.append('x-message-id', id) 
     let options = new RequestOptions({headers: this.headers}) 
     return this.http.delete(this.baseUrl + '/messages', options) 
      .map(res => res.json()) 
      .catch(this.errorHandler) 

    } 

    /** 
    * Error handler for all operations 
    * @param {Object} error 
    */ 

    errorHandler(error) { 
     return Observable.throw(error.json().error || 'Server Error') 
    } 
} 

而我的列表messages.component。 html:

<div class="row"> 
    <div class="col-lg-12"> 
     <div *ngIf="errors" class="error-container col-md-6"> 
      <div class="card card card-inverse card-danger"> 
       <div class="card-header"> 
        Error 
       </div> 
       <div class="card-block"> 
        <p>{{ errors }}</p> 
       </div> 
      </div> 
     </div> 
     <div *ngIf="success" class="error-container col-md-12"> 
      <div class="card card card-inverse card-primary"> 
       <div class="card-header"> 
        Success 
       </div> 
       <div class="card-block"> 
        <p>{{ success }}</p> 
       </div> 
      </div> 
     </div> 
     <div class="card" *ngIf="messages"> 
      <div class="card-header"> 
       <i class="fa fa-search"></i> Search 
      </div> 
      <div class="card-block"> 
       <input type="text" class="form-control" name="search_q" [(ngModel)]="search_q" (ngModelChange)="onSearch($event)"> 
      </div> 
     </div> 
     <div class="card" *ngIf="messages"> 
      <div class="card-header"> 
       <i class="fa fa-align-justify"></i> All Messages 
       <span class="total-count pull-right"> {{ total }}</span> 
      </div> 
      <div class="card-block"> 
       <table class="table table-condensed"> 
        <thead> 
         <tr> 
          <th> ID </th> 
          <th> Email </th> 
          <th> Message </th> 
          <th> Date sent </th> 
          <th> Actions </th> 
         </tr> 
        </thead> 
        <tbody> 
         <tr *ngFor="let message of messages | messageFilter:search_q"> 
          <td>{{ message._id }}</td> 
          <td>{{ message.email }}</td> 
          <td>{{ message.message | truncate :15 }}</td> 
          <td>{{ message.date_sent | date: 'dd/MM/yyyy' }}</td> 
          <td> 
           <a href="mailto:{{ message.email }}" class="btn btn-primary">Respond</a> 
           <button class="btn btn-danger" (click)="deleteMessage(message._id)"> Delete </button> 
          </td> 
         </tr> 
        </tbody> 
       </table> 
       <div class="pagination pull-right"> 
        <button class="pagination-button" id="prev-page" (click)="prevPage()" [disabled]="!hasPrevPage()">Prev</button> 
        <button class="pagination-button" id="next-page" (click)="nextPage()" [disabled]="!hasNextPage()">Next</button> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

任何想法或建議都非常受歡迎。

謝謝!

+0

錯誤指示問題是'list-messages.component.ngfactory.ts'文件行440.從那裏發佈代碼。 – Saravana

+0

這是在編譯時由角度生成的文件。我希望我可以訪問該文件,它會讓一切變得更加容易! –

回答

1

你所有的方法,其需要的參數應該有一個與之關聯的類型,例如你DeleteMessage可以參數ID應該有一個類型,

改變它,

deleteMessage(id:any) { 
} 
+0

不幸的是,我仍然遇到同樣的錯誤。 –

+0

只需檢查您是否傳遞模板中的那些方法的參數 – Sajeetharan

+0

我添加了我的模板。我真的看不到任何東西丟失。我公開了onSearch($ event)方法和deleteMessage(message._id)方法。其餘的只是一個for循環和一個好的HTML'HTML。 –

相關問題