Angular Final
Angular Final
npm install
créer un composant
ng g c register-user --skip--tests
3. dynamique: (temchi ll
app.composant.html w thotou bech
yothor )
app.composnat.hmt bech twali haka
<app-header></app-header>
<!-- dynamique-->
<router-outlet></router-outlet>
<hr>
<p> Copyrights</p>
donc f app-rootingModule nzid
const routes: Routes = [
{path:'home', component:ListPorductComponent},
{path:'addProduct', component:FormProductComponent},
{path:'**', component:NotFoundComponent},
];
NavBar (header)
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="">Navbar</a>
<button class="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle
navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page"
href="/home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/addProduct">Add product</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/user">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/addUser">Add User</a>
</li>
</ul>
</div>
</div>
</nav>
Model
tsconfig.js line 6
"strictPropertyInitialization": false,
el khedma mta les méthode tkoun f .ts mta3 composant eli bech
tekhdem bih
w madem hachtek b liste tji doub matheb donc thot el liste f méthode
onInit()
fi .ts
import { Produit } from 'src/app/model/Product' ;
</tbody>
2. les conditions
Recherche
1. declare une varriable bel champ eli bech tamel bih
recherche f .ts
a. public priceMax : any;
<form>
<div class="form-group">
<label> Search by Price</label> <br>
<input type="text" name="input" [(ngModel)]="priceMax"
class="form-group">
</div>
</form>
<label> Price</label>
<input type="number" name="price" [(ngModel)]="product.price"
class="form-control" required>
<br>
<label> Picture</label>
<input type="text" name="Picture" [(ngModel)]="product.picture"
class="form-control" required>
<br>
<label> Quantity</label>
<input type="number" name="Quantity"
[(ngModel)]="product.quantity" class="form-control" required>
<br>
</div>
<button class="btn btn-success" [disabled]="f.invalid"
(click)="save()">save</button>
</form>
zedna
.html
#f="ngForm"
[(ngModel)]="product.title"
ala kol input
[disabled]="f.invalid"
hethi ll button
.ts
public product : Product ;
constructor() {
this.product = new Product() ;
}
bel step hethi juste ki bech najouti w list ikoun nafs el list
(eli amlenelou add bel formulaire tzed f list )
maghir database
1. sna3a service mte3na
ng g s services/AnnoncesService --skip--test
2. hatina fih list eli hachetna biha
list : Product[] = [
{
id : 12 ,
title : 't-shirt' ,
quantity : 10 ,
like : 2 ,
price : 120 ,
picture : ''
},
{
id : 12 ,
title : 't-shirt' ,
quantity : 10 ,
like : 2 ,
price : 10 ,
picture : ''
},
{
id : 12 ,
title : 't-shirt' ,
quantity : 10 ,
like : 2 ,
price : 10 ,
picture : ''
}
]
url : "http://localhost:3000/"
constructor(private http : HttpClient) { }
getAllProducts(){
return this.http.get<Product[]>(this.url)
}
addProduct(p:Product){
return this.http.post(this.url , p) ;
}
updateProduct(){
deleteProduct(id : number){
return this.http.delete(this.url+id) ;
}
REMARQUE :
ki tebda condition ala input tekhdem b ngModel
ll devoir :
1. t7ather project fih css
2. tzid faza hethi mta model
"strictPropertyInitialization": false,
3. tzid service b heki ùta3 cmd … json
4. triguel module.ts
5. tkamel les methode mta3 service
6. fazet el button f projet mta3 revisionf
7. update nada