相关疑难解决方法(0)

Angular没有NameService的提供者

我在将类加载到Angular组件时遇到了问题.我一直试图解决它很长一段时间; 我甚至尝试在一个文件中加入它.我有的是:

Application.ts

/// <reference path="../typings/angular2/angular2.d.ts" />

import {Component,View,bootstrap,NgFor} from "angular2/angular2";
import {NameService} from "./services/NameService";

@Component({
    selector:'my-app',
    injectables: [NameService]
})
@View({
    template:'<h1>Hi {{name}}</h1>' +
    '<p>Friends</p>' +
    '<ul>' +
    '   <li *ng-for="#name of names">{{name}}</li>' +
    '</ul>',
    directives:[NgFor]
})

class MyAppComponent
{
    name:string;
    names:Array<string>;

    constructor(nameService:NameService)
    {
        this.name = 'Michal';
        this.names = nameService.getNames();
    }
}
bootstrap(MyAppComponent);
Run Code Online (Sandbox Code Playgroud)

服务/ NameService.ts

export class NameService {
    names: Array<string>;
    constructor() {
        this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
    }
    getNames()
    {
        return this.names;
    }
}
Run Code Online (Sandbox Code Playgroud)

我一直收到一条错误信息No …

typescript systemjs angular

302
推荐指数
10
解决办法
30万
查看次数

Angular2错误 - 我的登录组件没有提供程序错误

Angular2没有提供程序错误.

来自浏览器控制台的确切错误消息:"EXCEPTION:没有用户提供商!(登录 - >用户)".

打字稿编译器编译得很好.

模板加载正常.

但浏览器控制台有错误.

此外,您可以使用click和ng-model检查我的模板是否正确.

这是我的代码:

 import {Component, View, Injectable, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2';
 import {AuthService} from '../../authService';

 @Injectable()
 class User{
    email:string;
    password: string;
 } 

 @Component({
   selector: 'Login',  
 })

 @View({
   templateUrl: '/src/app/components/login/login.html',
   directives: [CORE_DIRECTIVES, FORM_DIRECTIVES],
 })

 @Injectable()
 export class Login {
   authService:AuthService;
   user: User;

   constructor(authService: AuthService, user: User){   
       this.authService = authService;
       this.user = user;
   }

   login = () => {
      console.log("login");
   }
 }
enter code here
Run Code Online (Sandbox Code Playgroud)

这是我的组件模板:

  <section class="container centered">
      <div class="row">
          <div class="well bs-component col-xs-12 col-xs-offset-0 …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

4
推荐指数
1
解决办法
3792
查看次数

标签 统计

angular ×2

typescript ×2

javascript ×1

systemjs ×1