2017-07-01 49 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';