2017-05-05 1 views
-2

JS 파일에서 가져온 함수를 호출하려고합니다 (src = "https://cdns.gigya.com/JS/gigya.js?apiKey= 3_sVidf29tz ")를 사용하여 ts 파일에서"declare var gigya; " 하지만 예기치 않은 토큰이 있습니다. 예기치 않은 토큰declare 문제를 해결하는 방법 var error : typescript에서 예기치 않은 토큰

무엇이 누락 되었습니까?

내 코드 : JS의 login.component.html

<body onload="callScreenSet()"> 
<div id="screen-set"></div> 
</body> 

index.html을

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>LanguageApp</title> 
    <base href="/"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
    <link href="/styles.css" rel="stylesheet" type="text/css"/> 
    <script type="text/javascript" lang="javascript" src="https://cdns.gigya.com/JS/gigya.js?apiKey=3_sVidf29tz"></script> 

</head> 

<body> 
    <app-root>Loading...</app-root> 
</body> 
</html> 

login.component.ts

import { Component, OnInit, AfterContentInit } from '@angular/core'; 
import any = jasmine.any; 
@Component({ 
    selector: 'app-root', 
    templateUrl: './login.component.html', 
    styleUrls: ['./login.component.css'] 
}) 
    declare var gigya; 
export class LoginComponent implements OnInit { 
    private _screenSet: string = 'Default-RegistrationLogin'; 
    private _containerID:string = 'screenSet'; 
    constructor(private srvLogin: LoginService) {} 
    ngOnInit() {} 
    public callScreenSet():void 
    { 
    gigya.accounts.showScreenSet({screenSet: this._screenSet,containerID: this._containerID}); 
    } 
} 

package.json

,691,363 (210 개)
{ 
    "name": "language-app", 
    "version": "0.0.0", 
    "license": "MIT", 
    "angular-cli": {}, 
    "scripts": { 
    "start": "ng serve", 
    "lint": "tslint \"src/**/*.ts\"", 
    "test": "ng test", 
    "pree2e": "webdriver-manager update", 
    "e2e": "protractor" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/common": "2.2.1", 
    "@angular/compiler": "2.2.1", 
    "@angular/core": "2.2.1", 
    "@angular/forms": "2.2.1", 
    "@angular/http": "2.2.1", 
    "@angular/platform-browser": "2.2.1", 
    "@angular/platform-browser-dynamic": "2.2.1", 
    "@angular/router": "3.2.1", 
    "auth0-lock": "^10.14.0", 
    "core-js": "^2.4.1", 
    "rxjs": "5.0.0-beta.12", 
    "ts-helpers": "^1.1.1", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "@angular/compiler-cli": "2.2.1", 
    "@types/jasmine": "2.5.38", 
    "@types/lodash": "4.14.50", 
    "@types/node": "^6.0.70", 
    "angular-cli": "1.0.0-beta.21", 
    "codelyzer": "~1.0.0-beta.3", 
    "jasmine-core": "2.5.2", 
    "jasmine-spec-reporter": "2.5.0", 
    "karma": "1.2.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-cli": "^1.0.1", 
    "karma-jasmine": "^1.0.2", 
    "karma-remap-istanbul": "^0.2.1", 
    "protractor": "4.0.9", 
    "ts-node": "1.2.1", 
    "tslint": "3.13.0", 
    "typescript": "~2.0.3", 
    "webdriver-manager": "10.2.5" 
    } 
} 

감사

+1

난 당신이'Component' @ 사이 아무것도 할 수 있다고 가정 할 것'그것이 연결되어 class' -은'import'과'@Component 사이에'declare' 라인을 이동하려고 줄? –

답변

2

귀하의 코드 :

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

declare가 장식 @Component 후 예기치입니다. 간단히 말해 같은 오류가 1***2과 같은 문법 오류 일 수 있습니다. 수정

declare var gigya; 
@Component({ 
    selector: 'app-root', 
    templateUrl: './login.component.html', 
    styleUrls: ['./login.component.css'] 
}) 
export class LoginComponent implements OnInit { 
관련 문제