Use of Material Icons following the documentation - html

I'm trying to implement and use material icons inside my angular 4 project, but i'm encountering a strange issue.
I have 2 different html files related to 2 differents modules:
interventi.component.html
sync.component.html
I've created a Material Module that imports and exports all the mat-components(modules) that i need, including the MatIconModule.
interventi.module.ts imports Material module.
sync.module.ts imports Material module.
Now listen to this :
1) In interventi.component.html i'm showing a material-icon with
<mat-icon aria-hidden="true" class="material-icons md-18" matSuffix (click)="customerModel = null">delete</mat-icon>
2) Inside sync.component.html I CAN'T DO THE SAME . Intellij recognize the tag but i will not see the icon, i will see "delete" as text, even if i try to copy all the code row shown above.
As the documentation of google says, I've put this link
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
inside my index.html.
Where i'm doing wrong?
I'm near to give in to common-use of material icons, putting the import link inside all the html.files that use material-icons.
I'm confused also by these twice methods to implement material icons...
For information completion, here's the Material Module:
import { NgModule } from '#angular/core';
import {CdkTableModule} from "#angular/cdk/table";
import {
[...others..],
MatIconModule,
[...others..]
} from '#angular/material';
#NgModule({
imports: [
[...others..],
MatIconModule,
[...others..]
],
exports: [
[...others..],
MatIconModule,
[...others..]
]
})
export class MaterialModule {}

Related

Cannot bind to 'matDatePicker' since isn't property of 'input', despite importing everything

I'm attempting to integrate a very basic date picker into my Angular project. The Angular CLI version is 6.2.9.
My HTML was taken straight from the Angular docs.
<mat-form-field appearance="fill">
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
This returned an error saying
Can't bind to 'matDatepicker' since it isn't a known property of 'input'
After a quick search I found this question that told me to include some imports, which I did adding the following to the very top of my TS code.
import { MatNativeDateModule, MatDatepickerModule, } from '#angular/material';
#NgModule({
declarations: [
HomeComponent
],
imports: [
MatDatepickerModule,
MatNativeDateModule,
FormsModule,
ReactiveFormsModule
]
})
Despite this, I'm continuing to receive the exact same error message. Have I forgotten something else in the TS file? Do I have to include something after my 'export class'? Or is this type of action just not compatible with my Angular version? Any help is appreciated.
Have you tried changing material modules imports to this?
import {MaterialModule} from '#angular/material';
#NgModule({
imports: [
MdDatepickerModule,
MdNativeDateModule,
FormsModule,
ReactiveFormsModule
]
})
Refer this article for more details this
Because it says MaterialModule Removed. please use separate module instead.
Hope this'll help.

Icons not being displayed in Angular Material List

I am attempting to display a list of the names of users of my application. Included
in the display is supposed to be an icon button which will perform some action
when pressed. I am using Angular Material components.
I believe I have all the important imports to the module. The code below shows
the material design components I imported:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { RouterModule, Routes } from '#angular/router';
import { MatListModule } from '#angular/material/list';
import { MatToolbarModule,
MatCardModule,
} from '#angular/material';
import { routeCmp } from './app.router';
import { NewuserModule } from './newuser/newuser.module';
import {MatIconModule} from '#angular/material';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MainComponent } from './main/main.component';
#NgModule({
declarations: [
AppComponent,
MainComponent,
],
imports: [
BrowserModule,
MatToolbarModule,
MatCardModule,
MatListModule,
MatIconModule,
BrowserAnimationsModule
],
// the rest of the code omitted for brevity
})
export class AppModule { }
Based on examples I've seen on the Internet, I have the following HTML for my
display:
<mat-nav-list>
<mat-list-item *ngFor="let names of userNames">
<div matLine>{{ names }}</div>
<button mat-icon-button>
<mat-icon>info</mat-icon>
</button>
</mat-list-item>
</mat-nav-list>
Note that userNames is (currently) just an array of strings.
My code is similar to the code shown below, which is taken from an example at
https://stackblitz.com/edit/list-examples?file=app%2Fnav-list%2Fnav-list.component.html
<h5>Complex Nav List</h5>
<mat-nav-list>
<mat-list-item *ngFor="let link of links">
<a matLine href="javascript:void(0)">{{ link }}</a>
<button mat-icon-button>
<mat-icon>info</mat-icon>
</button>
</mat-list-item>
</mat-nav-list>
The display from the example is shown in the picture below:
Unfortunately, what I am seeing instead is a button and text:
Obviously, I am missing something. There is something not described in the example that
makes it work. I did try recreating the example code in my own development setup, based
on what I downloaded from the site. The example code failed to properly display the
icon in my environment.
Can someone tell me what I am missing here? How can I get my list to properly display
the icons in my list?
You need to import Material Icons fonts into your project.
In index.html, add the following code.
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Since you are using mat-icon-button, you also need to import MatButtonModule into your AppModule imports.
You appear to be missing the MatButtonModule in your AppModule's imports.

Angular router link to element with a specified id within the page

I'm using Angular Router and I'm trying to link to a sub-component in another route by id. Basically what would usually be done using the <a href="www.url.com/profile/#profile-header-id">.
I'm not sure if there's a built-in way for the Angular router to do this, but if not perhaps I can manually trigger the link at a later point when I know the element has been rendered.
The issue isn't linking to another route which of course is done with the Link from the Angular router. The issue is linking to an element which is found in the rendered HTML of the linked component.
Less Abstract Code Example:
So let's say my router in the app.module.ts file is
`const routes = [
{ path: '', component: HomeComponent},
{ path: '#section3', component: HomeSection3Component},
{ path: 'B', component: BComponent},
];`
Now in component OtherComponent, I want a Link that not only takes me to the home page route ' ', but also scrolls to the element of id #section3, thereby skipping all the irrelevant stuff.
My home component has nested components for each one of the sections of the page. Each section/component has an id.
home.component.html
`<main>
<app-section1></app-section1>
<app-section2></app-section2>
<app-section3></app-section3>
</main>`
However, all I can see is a blank page when clicking the button <button routerLink="#section3">Go to homepage section 3</button> on the B page.
The most elegant solution is just to add a fragment property to add the #section3 to the URL and then make it jump to this section with an anchor tag.
<div [routerLink]="['']" fragment="section3">
Jump to 'Section3' anchor
</div>
Use the routerLink directive combined with its fragment input property.
<a routerLink fragment="section3">Section 3</a>
With your routes, the rendered DOM is
Section 3
Make sure that you have imported RouterModule in the declaring module of the component in which you use the routerLink directive. Example:
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
import { RouterModule } from '#angular/router';
#NgModule({
declarations: [
HomeComponent,
HomeSection1Component
HomeSection2Component,
HomeSection3Component,
],
imports: [
CommonModule,
RouterModule,
],
})
export class HomeModule {}

Angular does not recognise a selector within Template even if it has been declared in Component

I can't work out why Angular will not allow me to reference my components selector. I have a page which when you click on a list item the page should bring up another templates html. This is my code.
The error I keep receiving is 'message-component' is not a known element:
1. If 'message-component' is an Angular component, then verify that it is part of this module.
2. If 'message-component' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message.
Messages.component.html
<div id="Case" class="w3-container city" style="display:none">
<h2>Case</h2>
<message-case> </message-case>
</div>
I don't understand why it is giving me this error when the Message Component is declared and imported in both the NgModule and within the component.
Messages.Module.ts
#NgModule
({
imports: [SharedModule],
declarations: [
MessagesComponent,
MessageCaseComponent,
MessagesFilterPipe,
CreateMessageComponent,
],
})
Finally this is the file I am trying to display using the components selector
import { Component, OnInit } from '#angular/core';
import { IMessage } from './message';
import { ActivatedRoute, Router, Params } from '#angular/router';
import {MessagesComponent} from './messages.component';
import {CreateMessageComponent} from './createmessage.component';
#Component
({
moduleId: module.id,
selector: 'message-case',
templateUrl: 'message-case.html'
})
All help would be appreciated! I'm seemingly at a dead end right now.
Firstable the name file is wrong you putted this filename in the description
"Messages.component.html"
And the path of the template must contains "./" if it is in the same folder if it is in another folder you must put the relative path folder/file
#Component
({
moduleId: module.id,
selector: 'message-case',
templateUrl: './Messages.component.html'
})

Angular 2 first app works, second app don't

I tried to create a angular2 application that loads two components.
The first component called app works fine.
but the second component don't (called app-second).
index.html code
<h1>Demo of Angular 2 using ASP.NET 5 with Visual Studio 2015</h1>
<app>Loading...</app>
<br />
<app-second>Loading...</app-second>
app.ts code
import {Component} from 'angular2/core';
#Component({
selector: 'app',
template: 'My First Angular 2 App'
})
export class AppComponent {}
app-second.ts code
import {Component} from 'angular2/core';
#Component({
selector: 'app-second',
template: 'My First Angular 2 App'
})
export class AppSecondComponent{}
A Snapshot:
Can anybody tell me what is the error here?
Thanx.
You need to bootstrap your second app too.
//Importing bootstrap to instantiate your app
import {bootstrap} from 'angular2/platform/browser'
//importing the components you need to load
import {AppComponent} from './app/app'
import {AppSecondComponent} from './app/app-second'
//instantiating the components
bootstrap(AppComponent);
bootstrap(AppSecondComponent);
hope this helps.
You need to bootstrap both components
bootstrap(AppComponent, ...);
bootstrap(AppSecondComponent, ...);