Manish Angular Notes
Manish Angular Notes
command: ng g m approutingModule
ng g m approutingModule --flat
(flat is used for puts the file in src/app instead of its own folder)
step2. imports all component which we want to display by routing in app routing
module. like
we can copy this by app-module,ts file where all component is already imported.
for example
];
step 4. add routerlink where we want to link any component its work like a ancher
tag in html
routerLink="pathname"
example: <router-outlet></router-outlet>
imports: [
BrowserModule,
AppRoutingModule,
FormsModule
],
step3: add ngModel for two way data binding in input tag in html file
step4: declear expression type in .ts file like it will string or number etc.
for example
Name;
{{ Interpolationtype }}
for example
imgurl="assets/logo.png";
function()
block of code;
for example
syntax:
example:
in ts file
(Note : first declare the variable by let keyword binding the property by
propertybinding the use of keywords the arrayname where we store the
elements. then bind the property like value .then open ts file and decare array
with same name and stores the elements.)
first create a class that capture their changes and update an instance of a model.
example:
constructor(
){ }
then open you component .ts file where you want to write the form and import
the hero class.
for example :
imports: [
FormsModule
<form>
<div class="form-group">
<label for="name">Name</label>
</div>
</form>
for example
<form #heroForm="ngForm"></form>
.ng-valid[required], .ng-valid.required
.ng-invalid:not(form) {
border-left: 5px solid #a94442; /* red */
firstly make sure you have done template driven validation already.because it
needed in validation.
Firstly we have need to export ngModel in a local variable we can export ngModel
by this way
#name="ngModel"
class="alert alert-danger"></div>
(here name is a local variable which we use. and invalid , dirty and touched is
predefine class of ngForm)
then we can use multiple condition and error under this like
class="alert alert-danger">
<div *ngIf="name.errors.required">
Name is required.
</div>
<div *ngIf="name.errors.minlength">
</div>
<div *ngIf="name.errors.forbiddenName">
</div>
</div>
<form #registrationclassForm="ngForm">
<div class="form-group">
<label for="name">Name</label>
class="alert alert-danger">
<div *ngIf="name.errors.required">
Name is required.
</div>
<div *ngIf="name.errors.minlength">
</div>
<div *ngIf="name.errors.forbiddenName">
</div>
</div>
</div>
</form>
Cmd command is
After this we Have need to import animation package in app module for enable
animation support.
...
imports: [BrowserAnimationsModule],
...
})
@NgModule({
...
...
})
Including a theme is required to apply all of the core and theme styles to your
application.
For this you can add or import idigo-pink.css in your globle css.
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
If your project is using SystemJS for module loading, you will need to
add @angular/material and@angular/cdk to the SystemJS configuration.
map: {
// ...
'@angular/material': 'npm:@angular/material/bundles/material.umd.js',
'@angular/cdk/platform': 'npm:@angular/cdk/bundles/cdk-
platform.umd.js',
'@angular/cdk/a11y': 'npm:@angular/cdk/bundles/cdk-a11y.umd.js',
// ...
'hammerjs': 'npm:hammerjs',
},
packages: {
//...
});