2017-07-01 50 views
0

我很抱歉問這個愚蠢的問題。我是Angular 2的新手,並且在我的應用程序使用的API中遇到了一些問題。消耗的網絡API坐在下面的文件夾結構Angular 2錯誤引用服務proxy-asd:18錯誤:(SystemJS)意外令牌<SyntaxError:意外令牌<

- src 
    - app 
    - Registration 
     - dashboard.component.html 
     - dashboard.component.ts 
    - Shared 
    - service-proxies 
    - service.proxies.ts 
    - service-proxy.module.ts 

代碼的代理內正常工作,因爲我提出這兩個應用程序文件夾中的文件,一切工作正常。我收到以下錯誤,如果文件的共享目錄內

Error: (SystemJS) Unexpected token < 
SyntaxError: Unexpected token < 
    at eval (<anonymous>) 
    at Object.eval (http://localhost:51860/src/app/registration/dashboard.component.js:14:25) 
    at eval (http://localhost:51860/src/app/registration/dashboard.component.js:53:4) 
    at eval (http://localhost:51860/src/app/registration/dashboard.component.js:54:3) 
Evaluating http://localhost:51860/src/Shared/service-proxies/service-proxies 
Evaluating http://localhost:51860/src/app/registration/dashboard.component.js 
Evaluating http://localhost:51860/src/app/app.module.js 
Evaluating http://localhost:51860/src/main.js 
Error loading http://localhost:51860/src/main.js 
    at eval (<anonymous>) 
    at Object.eval (http://localhost:51860/src/app/registration/dashboard.component.js:14:25) 
    at eval (http://localhost:51860/src/app/registration/dashboard.component.js:53:4) 
    at eval (http://localhost:51860/src/app/registration/dashboard.component.js:54:3) 
Evaluating http://localhost:51860/src/Shared/service-proxies/service-proxies 
Evaluating http://localhost:51860/src/app/registration/dashboard.component.js 
Evaluating http://localhost:51860/src/app/app.module.js 
Evaluating http://localhost:51860/src/main.js 
Error loading http://localhost:51860/src/main.js 

就是它引發錯誤的行線14以下是輸出爲我dashboard.component.js

誤差拋在以下行

var service_proxies_1 = require("../../Shared/service-proxies/service-proxies"); 

下面是我的文件從瀏覽器的完整輸出。

(function(System, SystemJS) {(function(require, exports, module, __filename, __dirname, global, GLOBAL) {"use strict"; 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 
    return c > 3 && r && Object.defineProperty(target, key, r), r; 
}; 
var __metadata = (this && this.__metadata) || function (k, v) { 
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 
}; 
var core_1 = require("@angular/core"); 
var router_1 = require("@angular/router"); 
var hero_service_1 = require("../hero.service"); 
var service_proxies_1 = require("../../Shared/service-proxies/service-proxies"); 
var DashboardComponent = (function() { 
    function DashboardComponent(injector, _storeServiceProxy, heroService, route, router) { 
     this._storeServiceProxy = _storeServiceProxy; 
     this.heroService = heroService; 
     this.route = route; 
     this.router = router; 
     this.heroes = []; 
     this.var1 = route.snapshot.params['id']; 
     console.log(this.var1); 
    } 
    DashboardComponent.prototype.ngOnInit = function() { 
     var _this = this; 
     this.heroService.getHeroes() 
      .then(function (heroes) { return _this.heroes = heroes.slice(1, 5); }); 
     this.var2 = this.var1; 
     console.log(this.var2); 
     this._storeServiceProxy.getStoresByShortCode("") 
      .subscribe(function (result) { 
      var test = result.isActive; 
      var testTwo = result.isActive; 
     }); 
    }; 
    return DashboardComponent; 
}()); 
DashboardComponent = __decorate([ 
    core_1.Component({ 
     selector: 'my-dashboard, ngbd-accordion-static', 
     templateUrl: "app/registration/dashboard.component.html", 
     styleUrls: ["app/registration/dashboard.component.css"] 
    }), 
    __metadata("design:paramtypes", [core_1.Injector, 
     service_proxies_1.StoreServiceProxy, 
     hero_service_1.HeroService, 
     router_1.ActivatedRoute, 
     router_1.Router]) 
], DashboardComponent); 
exports.DashboardComponent = DashboardComponent; 
//# sourceMappingURL=dashboard.component.js.map 
}).apply(__cjsWrapper.exports, __cjsWrapper.args); 
})(System, System); 

有人可以讓我知道我做錯了什麼。記住,如果我將文件的位置更改爲應用程序文件夾,一切正常。請幫助

編輯

這裏是dahsboard.component.ts文件

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


import { Hero } from '../hero'; 
import { HeroService } from '../hero.service'; 
import { StoreServiceProxy } from '../../Shared/service-proxies/service-proxies'; 

@Component({ 
    selector: 'my-dashboard, ngbd-accordion-static', 
    templateUrl: './dashboard.component.html', 
    styleUrls: ['./dashboard.component.css'] 
}) 

export class DashboardComponent implements OnInit { 
    private var1: string; 
    private var2: string; 
    heroes: Hero[] = []; 

    constructor(
     injector: Injector, 
     private _storeServiceProxy: StoreServiceProxy, 
     private heroService: HeroService, 
     private route: ActivatedRoute, 
     private router: Router 
    ) { 
     this.var1 = route.snapshot.params['id']; 
     console.log(this.var1); 

    } 

    ngOnInit(): void { 
     this.heroService.getHeroes() 
      .then(heroes => this.heroes = heroes.slice(1, 5)); 

     this.var2 = this.var1; 
     console.log(this.var2); 

     this._storeServiceProxy.getStoresByShortCode("") 
      .subscribe(result => { 
       var test = result.isActive; 
       var testTwo = result.isActive; 
      }); 
    } 
} 
+0

這將是一個很好的幫助在確定問題,如果您粘貼ts文件而不是js文件的角度。我可以發佈代碼片段,這也將有所幫助 –

回答

0

原因的錯誤是指文件不可用。由於不可用的文件index.html內容正在加載,其中<作爲第一個字符。 要修復它,你必須確定你的文件可用的路徑。

要基於文件夾結構,你共享的開始,改變

import { StoreServiceProxy } from '../../Shared/service-proxies/service-proxies'; 

import { StoreServiceProxy } from '../../Shared/service-proxies/service.proxies'; 

import { StoreServiceProxy } from '../../Shared/service-proxies/service-proxy.module';