2017-06-22 45 views
1

我正在用angular-cli開發Angular2。angular-cli.json?說「時刻還沒有定義」

我不完全知道如何設置我的源碼,請參閱其他外部CSS',JavaScript庫。

首先,這裏是我的angular-cli配置。 (嗯,你知道的,我第一件事裝,許多圖書館在這裏製作另一頁)

"main": "main.ts", 
    "test": "test.ts", 
    "tsconfig": "tsconfig.json", 
    "prefix": "app", 
    "mobile": false, 
    "styles": [ 
    "../node_modules/admin-lte/bootstrap/css/bootstrap.min.css", 
    "../node_modules/admin-lte/dist/css/AdminLTE.min.css", 
    "../node_modules/admin-lte/dist/css/skins/_all-skins.min.css", 
    "../node_modules/admin-lte/dist/css/skins/skin-blue.min.css", 
    "../node_modules/admin-lte/plugins/colorpicker/bootstrap-colorpicker.min.css", 
    "../node_modules/admin-lte/plugins/daterangepicker/daterangepicker.css", 
    "../node_modules/admin-lte/plugins/timepicker/bootstrap-timepicker.min.css", 
    "../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css", 
    "../node_modules/bootstrap-fileinput/css/fileinput.min.css", 
    "../node_modules/fullcalendar/dist/fullcalendar.min.css", 
    "../node_modules/fullcalendar/dist/fullcalendar.print.css", 
    "../node_modules/fullcalendar-scheduler/dist/scheduler.min.css", 
    "../node_modules/morris.js/morris.css", 
    "../node_modules/flickity/dist/flickity.min.css", 
    "../node_modules/font-awesome/css/font-awesome.min.css", 
    "../node_modules/ionicons/dist/css/ionicons.min.css", 
    "../node_modules/icheck/skins/all.css", 
    "../node_modules/icheck/skins/flat/blue.css", 
    "../node_modules/icheck/skins/minimal/blue.css", 
    "admin.less", 
    "styles.css" 
    ], 
    "scripts": [ 
    "../node_modules/jquery/dist/jquery.min.js", 
    "../node_modules/jqueryui/jquery-ui.min.js", 
    "../node_modules/admin-lte/bootstrap/js/bootstrap.min.js", 
    "../node_modules/admin-lte/dist/js/app.min.js", 
    "../node_modules/admin-lte/plugins/chartjs/Chart.min.js", 
    "../node_modules/admin-lte/plugins/colorpicker/bootstrap-colorpicker.min.js", 
    "../node_modules/admin-lte/plugins/datatables/jquery.dataTables.min.js", 
    "../node_modules/admin-lte/plugins/datatables/dataTables.bootstrap.min.js", 
    "../node_modules/admin-lte/plugins/daterangepicker/daterangepicker.js", 
    "../node_modules/admin-lte/plugins/fastclick/fastclick.min.js", 
    "../node_modules/admin-lte/plugins/input-mask/jquery.inputmask.js", 
    "../node_modules/admin-lte/plugins/input-mask/jquery.inputmask.date.extensions.js", 
    "../node_modules/admin-lte/plugins/input-mask/jquery.inputmask.extensions.js", 
    "../node_modules/admin-lte/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js", 
    "../node_modules/admin-lte/plugins/jvectormap/jquery-jvectormap-world-mill-en.js", 
    "../node_modules/admin-lte/plugins/select2/select2.full.min.js", 
    "../node_modules/admin-lte/plugins/slimScroll/jquery.slimscroll.min.js", 
    "../node_modules/admin-lte/plugins/timepicker/bootstrap-timepicker.min.js", 
    "../node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js", 
    "../node_modules/bootstrap-fileinput/js/fileinput.min.js", 
    "../node_modules/bootstrap-fileinput/js/plugins/sortable.min.js", 
    "../node_modules/bootstrap-fileinput/js/plugins/purify.min.js", 
    "../node_modules/bootstrap-fileinput/js/locales/ja.js", 
    "../node_modules/bootstrap-fileinput/themes/fa/theme.min.js", 
    "../node_modules/flickity/dist/flickity.pkgd.min.js", 
    "../node_modules/fullcalendar/dist/fullcalendar.min.js", 
    "../node_modules/fullcalendar/dist/locale/ja.js", 
    "../node_modules/fullcalendar/dist/gcal.min.js", 
    "../node_modules/fullcalendar-scheduler/dist/scheduler.min.js", 
    "../node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.min.js", 
    "../node_modules/blueimp-load-image/js/load-image.all.min.js", 
    "../node_modules/raphael/raphael.min.js", 
    "../node_modules/moment/moment.js", 
    "../node_modules/morris.js/morris.min.js", 
    "../node_modules/jquery-knob/dist/jquery.knob.min.js", 
    "../node_modules/icheck/icheck.min.js", 
    "../node_modules/html5shiv/dist/html5shiv.min.js", 
    "../node_modules/respond.js/dest/respond.min.js", 
    "assets/js/ajax-load.js", 
    "assets/js/form_parts_initialize.js", 
    "assets/js/sidebar_addActive.js", 
    "scripts.js" 
    ], 
    "environmentSource": "environments/environment.ts", 
    "environments": { 
    "dev": "environments/environment.ts", 
    "prod": "environments/environment.prod.ts" 
    } 

其實,我成功的角度編譯,但nginx的運行時,它下面的嘔吐圖像2級的錯誤。

enter image description here

和這裏的下面tsconfig.json。

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    "declaration": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": ["es6", "dom"], 
    "mapRoot": "./", 
    "module": "es6", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "target": "es5", 
    "typeRoots": [ 
     "../node_modules/@types", 
     "../node_modules/moment" 
    ] 
    } 
} 

但還有另一個。 typings.d.ts(我不知道我應該用這個做什麼)

// Typings reference file, you can add your own global typings here 
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 

declare var System: any; 

這是我製造的源代碼。 (你知道,它是基於adminLTE登錄頁面上。我到這裏就要使用I檢查插件。)

import { Component, OnInit } from '@angular/core'; 
import { Router } from '@angular/router'; 


@Component({ 
    selector: 'app-login', 
    templateUrl: './login.component.html', 
    styleUrls: ['./login.component.css'] 
}) 
export class LoginComponent implements OnInit { 

    bodyClasses:string = "login-page"; 
    body = document.getElementsByTagName('body')[0]; 
    icheck: JQuery; 

    constructor(private router:Router) { 
    } 

    ngOnInit() { 
    //Add the login-page class to the body 
    //$('body').addClass(this.bodyClasses); 
    this.body.classList.add(this.bodyClasses); //add the class 

    this.icheck = jQuery('input[type="checkbox"].minimal-blue').iCheck({ 
     checkboxClass: "icheckbox_flat-blue", 
     radioClass: "iradio_flat-blue", 
     increaseArea: "20%" // optional 
    }); 
    } 

    ngOnDestroy() { 
    //remove the login-page class to the body 
    //$('body').removeClass(this.bodyClasses); 
    this.body.classList.remove(this.bodyClasses); 
    } 

    ngAfterViewInit() { 
    } 

} 

能給我什麼建議嗎?

+0

爲什麼' 「../ node_modules /時刻」''中設置typeRoots'?即時文件夾中的@ @類型? –

+0

@suraj好吧,沒有@ types/moment npm存儲庫。而angular2-adminLTE原始源代碼就這樣寫了tsconfig.json。僅供參考,我沒有處理tsconfig.json –

回答

0

我建議你使用npm來安裝時刻,並將它們導入到你使用它的任何地方。

  • npm install moment --save
  • 在使用每一刻打字稿文件import moment from 'moment'
+0

感謝您的意見。實際上,我以另一種方式解決了這個問題。不知何故,angular-cli.json正在按順序閱讀「腳本」順序。我沒有想到這一點。我的意思是,當你可以在顯然依賴於moment.js的「scripts」屬性上寫datepicker,fullcalendar時,你首先需要「moment.js」。底線是角度cli很爛。不管怎麼說,還是要謝謝你。 –

+0

如果您使用npm進行依賴關係管理,則不會出現此問題。 ''angular-cli.json''中的''scripts''只能用於不輸出模塊的第三方依賴項。時刻呢。按預期使用它,你不會有問題... –