我想在Angular 4中使用jquery.js和materialize.js以及它們的.min.js文件。因爲有一些html效果可以與它們一起工作。我想使用jquery.js和materialize.js
這是我的模塊
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
/*import { NgbModule } from '@ng-bootstrap/ng-bootstrap';*/
import { LoginComponent } from './login.component';
@NgModule({
declarations: [
LoginComponent
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule
],
providers: [LoginComponent],
bootstrap: [LoginComponent]
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule)
,這是我component.ts
import { Component } from '@angular/core';
import { NgForm } from '@angular/forms';
@Component({
selector: 'login-form',
templateUrl: './login.component.html',
styleUrls: ['./../assets/css/main.css',
'./../assets/css/materialize.css',
'./../assets/css/materialize.min.css']
})
export class LoginComponent {
authenticateUser(loginForm: NgForm) {
var data = JSON.stringify(loginForm);
console.log(loginForm);
console.log(data);return false;
// {email: '...', password: '...'}
// ... <-- now use JSON.stringify() to convert form values to
json.
}
}
這是HTML
<body>
<div class="container">
<div class="row">
<div class="col s12 m5 offset-m3 l5 offset-l3">
<div class="login-row">
<div class="login">
<h4>LOGIN</h4>
</div>
<div class="login-data">
<form #loginForm="ngForm">
<div class="row">
<div class="input-field col s12
m12 l12">
<input name="username"
id="username" type="text" class="validate" ngModel>
<label>Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12
m12 l12 ">
<input name="password"
id="password" type="password" class="validate" ngModel>
<label
for="password">Password</label>
</div>
</div>
<div class="col s12 m12 l12 right-
align">
<a class="waves-effect waves-light
btn" type="ngSubmit"
(click)="authenticateUser(loginForm.value)">login</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-1.11.2.min.js"></script>
<script src="assets/js/materialize.min.js"></script>
</body>
到目前爲止您做了什麼?已經有一個項目了嗎?你使用任何起動器項目? – Doomenik
只要做npm install --save jquery,並確保你將它的參考添加到index.html。 – Gayathri
謝謝,是的,我正在一個項目上工作。我該怎麼做才能實現js –