[英]Angular2 : Using Jquery in Angular2 : Error: No provider for Token jQuery
[英]Angular2 error - No provider error for my login component
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
這是我的組件模板:
<section class="container centered">
<div class="row">
<div class="well bs-component col-xs-12 col-xs-offset-0 col-sm-12 col-sm-offset-0 col-md-6 col-md-offset-3 col-lg-offset-4 col-lg-4">
<h3>Log In</h3>
<form class="padding-top-20" role="form" novalidate>
<div class="form-group">
<input class="form-control" type="text" name="email" id="email" placeholder="Email Address" [(ng-model)]="user.userName" required autofocus />
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" id="password" placeholder="Password" [(ng-model)]="user.password" required autofocus />
</div>
<button class="btn btn-primary btn-wide" type="submit" (click)="login()">Log In</button>
<div class="padding-top-20 padding-bottom-20">
<a href="/forgotpassword" title="Forgot Password?">Forgot Password?</a>
</div>
</form>
</div>
</div>
</section>
以下是瀏覽器控制台錯誤的屏幕截圖:
要注冊注射劑,請在組件定義中使用:
@Component({
selector: 'Login',
providers: [Login, User]
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.