2016-08-15 165 views
1

我是新來的角,我建立了一個小應用程序,需要顯示一個可排序的表。它在開發模式下的Angular-cli開發服務器上運行良好(使用ng serve)。ng build --prod cause模板解析錯誤

我試過用ng2表和angular-table庫實現表,所以我懷疑這不是與這些庫中的任何一個關聯的問題。

然而,當我建立使用ng build --prod部署應用到我的臨時服務器,我收到了瀏覽器控制檯中以下錯誤,當我嘗試訪問該應用程序」

zone.js:461 Unhandled Promise rejection: Template parse errors: 
Can't bind to 'rowsOnPageSet' since it isn't a known property of 'mfBootstrapPaginator'. ("      <td colspan="3"> 
             <mfBootstrapPaginator [ERROR ->][rowsOnPageSet]="[10,25,100]"></mfBootstrapPaginator> 
            </td> 
    "): [email protected]:62 ; Zone: <root> ; Task: Promise.then ; Value: 

Template parse errors:↵Can't bind to 'rowsOnPageSet' since it isn't a known property of 'mfBootstrapPaginator'. ("      <td colspan="3">↵          <mfBootstrapPaginator [ERROR ->][rowsOnPageSet]="[10,25,100]"></mfBootstrapPaginator>↵         </td>↵  "): [email protected]:62" 

我已經更新了我的代碼,以便它是所有采用了棱角分明2.0.0RC5運行,也就是說,以便它使用新的@NgModule裝飾。

任何幫助或建議,您可以提供將不勝感激。我在這裏結束。

感謝

JT

注:我試着暫時specifiying的DataTableDirectives作爲組件的@Component裝飾下一個指令,但這並沒有幫助。

app.module.ts

import {NgModule} from '@angular/core'; 
import {BrowserModule} from '@angular/platform-browser'; 
import {HttpModule} from '@angular/http'; 
import {DataTableDirectives} from 'angular2-datatable/datatable'; 
import {AppComponent, APP_ROUTER_PROVIDERS, APP_ROUTES} from './'; 
import {MapToIterable} from './utils'; 
import {ServerDataService} from './services'; 
import {HomeComponent, DecoderStatusComponent, ActivityListComponent, PassingsComponent} from './components'; 


@NgModule({ 
    imports: [ 
     APP_ROUTES, 
     BrowserModule, 
     HttpModule 
    ], 
    declarations: [ 
     AppComponent, 
     DecoderStatusComponent, 
     ActivityListComponent, 
     PassingsComponent, 
     HomeComponent, 
     MapToIterable, 
     DataTableDirectives 
    ], 
    providers: [ 
     APP_ROUTER_PROVIDERS, 
     ServerDataService 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { 
} 

系統config.ts

/******************************* 
* User Configuration. 
*******************************/ 

/** Map relative paths to URLs. */ 
const map: any = { 
    'lodash':    'vendor/lodash', 
    'rxjs':     'vendor/rxjs', 
    'angular2-datatable': 'vendor/angular2-datatable', 
    'ng2-bootstrap':  'vendor/ng2-bootstrap', 
    'moment':    'vendor/moment' 
}; 

/** User packages configuration. */ 
const packages: any = { 
    'lodash':    { defaultExtension: 'js', main: 'lodash.js' }, 
    'rxjs':     { defaultExtension: 'js' }, 
    'angular2-datatable': { defaultExtension: 'js' }, 
    'moment':    { format: 'cjs', defaultExtension: 'js' }, 
    'ng2-bootstrap':  { format: 'cjs', defaultExtension: 'js' } 
}; 



/******************************* 
* Everything underneath this line is managed by the CLI. 
*******************************/ 
const barrels: string[] = [ 
    // Angular specific barrels. 
    '@angular/core', 
    '@angular/common', 
    '@angular/compiler', 
    '@angular/forms', 
    '@angular/http', 
    '@angular/router', 
    '@angular/platform-browser', 
    '@angular/platform-browser-dynamic', 

    // Thirdparty barrels. 


    // App specific barrels. 
    'app', 
    'app/shared', 
    'app/components', 
    'app/model', 
    'app/services', 
    'app/utils' 
    /** @cli-barrel */ 
]; 

const cliSystemConfigPackages: any = {}; 
barrels.forEach((barrelName: string) => { 
    cliSystemConfigPackages[barrelName] = { main: 'index' }; 
}); 

/** Type declaration for ambient System. */ 
declare var System: any; 

// Apply the CLI SystemJS configuration. 
System.config({ 
    map: { 
     '@angular': 'vendor/@angular', 
     'rxjs': 'vendor/rxjs', 
     'main': 'main.js' 
    }, 
    packages: cliSystemConfigPackages 
}); 

// Apply the user's configuration. 
System.config({ map, packages }); 

Passings.html

<div class="panel-body"> 
        <div class="row"> 
         <div class="col-xs-12 col-md-12"> 
          <table class="table table-striped" [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="10"> 
           <thead> 
           <tr> 
            <th>Passing</th> 
            <th>Date</th> 
            <th>Time</th> 
           </tr> 
           </thead> 
           <tbody> 
           <tr *ngFor="let item of mf.data"> 
            <td>{{item[0]}}</td> 
            <td>{{item[1]}}</td> 
            <td>{{item[2]}}</td> 
           </tr> 
           </tbody> 
           <tfoot> 
           <tr> 
            <td colspan="3"> 
             <mfBootstrapPaginator [rowsOnPageSet]="[10,25,100]"></mfBootstrapPaginator> 
            </td> 
           </tr> 
           </tfoot> 
          </table> 
         </div> 
        </div> 
       </div> 

回答

1

OK,似乎 這是一個已知的問題。請參閱:

https://github.com/angular/angular/issues/10618

值得一通過此線程讀取,因爲它幾乎解釋了最全的問題。

現在,不要醜化你的代碼。如果您正在使用angular-cli,則可能需要開發構建版本直到下一個版本。

+0

是的,通過'ng build -prod'構建會引發這個錯誤,臨時解決方案是'ng build' – neilhem

相關問題