2017-08-23 15 views
0

このチュートリアルではNativeScriptについて説明してきましたが、いくつかのエラーが出ています。NativeScript TypeScriptの "Unterminated string literal error" app.component.ts

は、ここに私のapp.component.tsファイルです:

import { Component } from '@angular/core'; 

@Component ({ 
    selector: 'my-app', 
    template: ' 
    <ul> 
     <li><a [routerLink] = "['/Product']">Product</a></li> 
     <li><a [routerLink] = "['/Inventory']">Inventory</a></li> 
    </ul> 
    <router-outlet></router-outlet>' 
}) 
export class AppComponent { } 

私は活字体のプラグインとのAtomを使用している、と私はtemplate:にカーソルを合わせると、それは奇妙に思えるタイプ(property) template: booleanのだということを私に伝えます。 HTMLを1行に入れてみると、文字列型であるとわかります。テンプレートが複数の行にあることが気に入らないのとほとんど同じです。

とにかく私はNSにはかなり新しいので、このチュートリアルを進めたいと思うので、それは明らかなことかもしれません。私は密接にコピーするよう指示するコードをチェックしたが、何が間違っているかを見ることはできない。以下は私がアプリを実行しようとすると、私は見ているエラーです:あなたはtemplateプロパティに割り当てる

$ npm start 

> [email protected] prestart /Users/mb102/Angular-Projects/Demo 
> npm run build 


> [email protected] build /Users/mb102/Angular-Projects/Demo 
> tsc -p src/ 

src/app/app.component.ts(5,15): error TS1002: Unterminated string literal. 
src/app/app.component.ts(7,27): error TS1005: '>' expected. 
src/app/app.component.ts(7,43): error TS1005: ':' expected. 
src/app/app.component.ts(8,27): error TS1005: '>' expected. 
src/app/app.component.ts(8,45): error TS1005: ':' expected. 
src/app/app.component.ts(9,5): error TS1110: Type expected. 
src/app/app.component.ts(9,6): error TS1161: Unterminated regular expression literal. 
src/app/app.component.ts(10,20): error TS1110: Type expected. 
src/app/app.component.ts(10,21): error TS1161: Unterminated regular expression literal. 

npm ERR! Darwin 16.7.0 
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build" 
npm ERR! node v6.11.0 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] build: `tsc -p src/` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] build script 'tsc -p src/'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular-quickstart package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  tsc -p src/ 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular-quickstart 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular-quickstart 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /Users/mb102/Angular-Projects/Demo/npm-debug.log 

npm ERR! Darwin 16.7.0 
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 
npm ERR! node v6.11.0 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] prestart: `npm run build` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] prestart script 'npm run build'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular-quickstart package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  npm run build 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular-quickstart 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular-quickstart 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /Users/mb102/Angular-Projects/Demo/npm-debug.log 
+5

テンプレートプロパティに「代わりに」を使用しているようです。 – toskv

+0

TypeScript/JavaScriptの文字列は複数行ではありません。見積もりを開く場合は、同じ行で引用符を閉じる必要があります。文字列を複数の行に分散させるには、一連の文字列を連結する必要があります。テンプレートリテラルを使用することもできます。 https://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript – Amy

答えて

0

値は、複数行の文字列です。 はTypescriptでが許可されていません。 文字列を140文字以上にすることはお勧めできません(tslintを参考にしてください)、テンプレートをhtmlファイルに入れる方が良いでしょう。

ファイルに残しておきたい場合は、 '(一重引用符)の代わりに文字列を区切るために `(backtick-alt + 0096 on windows)文字を使用する必要があります。

関連する問題