I have an Angular 2 app where the default page is a toolbar. It displays properly, but for some reason it is displaying twice, i.e. two identical toolbars on top of each other.
Here is my app.html code:
<p-toolbar>
<div class="ui-toolbar-group-left">
<button pButton type="button" label="Home" routerLink="/"></button>
</div>
<div class="ui-toolbar-group-right">
<button pButton type="button" label="About" routerLink="/about"></button>
<i class="fa fa-bars"></i>
<button pButton type="button" icon="fa-cog" routerLink="/test"></button>
</div>
</p-toolbar>
<router-outlet></router-outlet>
Here is my app.module.ts file:
import { AppComponent } from "./components/app.component";
import { AboutComponent } from "./components/about.component";
import { TunerComponent } from "./components/tuner.component";
import { CoreService } from "./services/core.service";
import { routing } from "./app.routes";
import { NgModule } from "#angular/core";
import { BrowserModule } from "#angular/platform-browser";
import { FormsModule } from "#angular/forms";
import { HttpModule } from "#angular/http";
import { SliderModule } from "primeng/primeng";
import { ButtonModule } from "primeng/primeng";
import { PanelModule } from "primeng/primeng";
import { ToolbarModule } from "primeng/primeng";
#NgModule({
imports: [
BrowserModule,
routing,
FormsModule,
HttpModule,
PanelModule,
ToolbarModule,
ButtonModule,
SliderModule
],
declarations: [
AppComponent,
AboutComponent,
TunerComponent
],
providers: [
CoreService
],
bootstrap: [
AppComponent
],
})
export class AppModule { }
Here is my app.routes.ts files:
import { ModuleWithProviders } from "#angular/core";
import { Routes, RouterModule } from "#angular/router";
import { AppComponent } from "./components/app.component";
import { AboutComponent } from "./components/about.component";
import { TunerComponent } from "./components/tuner.component";
const appRoutes: Routes = [
{
path: "about",
component: AboutComponent
},
{
path: "tuner",
component: TunerComponent
},
{
path: "",
component: AppComponent,
}
];
export const appRoutingProviders: any[] = [
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
and here is my Index.cshtml file:
<cache vary-by="#Context.Request.Path">
<app>
Loading App Content...
</app>
</cache>
#section scripts {
<script src="~/vendor.bundle.js"></script> <!-- Vendor Bundle Includes all outside requirments -->
<script src="~/main.bundle.js"></script> <!-- Includes development code / Angular 2 -->
}
I've just updated from Angular RC4 to Angular 2.2.4. Everything seems in order, I'm unsure of why this is happening.
Related
I am using the Angular implementation of the IBM Carbon Design and IBM icons are not showing in some contexts.
What i'm supposed to get :
What i get :
Icons which appear in my header :
Here is my Angular config :
Here are the files where icons appear (header) :
app.module.ts
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
import { FormsModule } from '#angular/forms';
import { BrowserModule } from '#angular/platform-browser';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
// IBM Carbon Modules
import Notification20Icon from '#carbon/icons/es/notification/20';
import Switcher20Icon from '#carbon/icons/es/switcher/20';
import UserAvatar20Icon from '#carbon/icons/es/user--avatar/20';
import {
BreadcrumbModule, ButtonModule, GridModule,
IconModule, IconService, ListModule, TableModule,
TabsModule, TilesModule, UIShellModule
} from 'carbon-components-angular';
// App Modules
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './Components/header/header.component';
import { LandingComponent } from './Components/landing/landing.component';
import { ReposComponent } from './Components/repos/repos.component';
import { InfoModule } from './module/info/info.module';
#NgModule({
declarations: [
AppComponent,
HeaderComponent,
LandingComponent,
ReposComponent,
],
imports: [
BrowserModule,
ButtonModule,
AppRoutingModule,
CommonModule,
GridModule,
ListModule,
TabsModule,
TilesModule,
BrowserAnimationsModule,
FormsModule,
AppRoutingModule,
UIShellModule,
IconModule,
BreadcrumbModule,
TableModule,
InfoModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(protected iconService: IconService) {
iconService.registerAll([
Notification20Icon,
UserAvatar20Icon,
Switcher20Icon,
]);
}
}
header.component.html
<ibm-header name="[PW - Raceway]">
<ibm-header-navigation>
<ibm-header-item routerLink="landing">Landing</ibm-header-item>
<ibm-header-item routerLink="repos">Repositories</ibm-header-item>
<ibm-header-item routerLink="support">Support</ibm-header-item>
<ibm-header-menu title="Manage">
<ibm-header-item routerLink="link1">Link 1</ibm-header-item>
<ibm-header-item>Link 2</ibm-header-item>
<ibm-header-item>Link 3</ibm-header-item>
</ibm-header-menu>
</ibm-header-navigation>
<ibm-header-global>
<ibm-header-action title="action">
<svg ibmIcon="notification" size="20"></svg>
</ibm-header-action>
<ibm-header-action title="action">
<svg ibmIcon="user--avatar" size="20"></svg>
</ibm-header-action>
<ibm-header-action title="action">
<svg ibmIcon="switcher" size="20"></svg>
</ibm-header-action>
</ibm-header-global>
</ibm-header>
Here are the files where icons don't appear (kind of footer) :
info.module.ts
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
// IBM Carbon Modules
import Application32Icon from '#carbon/icons/es/application/32';
import Globe32Icon from '#carbon/icons/es/globe/32';
import PersonFavorite32Icon from '#carbon/icons/es/person--favorite/32';
import { GridModule, IconService } from 'carbon-components-angular';
// App Modules
import { CardComponent } from './card/card.component';
import { SectionComponent } from './section/section.component';
#NgModule({
declarations: [
CardComponent,
SectionComponent
],
imports: [
CommonModule,
GridModule,
],
providers: [],
exports: [
SectionComponent,
CardComponent
]
})
export class InfoModule {
constructor(protected iconService: IconService) {
iconService.registerAll([
Application32Icon,
Globe32Icon,
PersonFavorite32Icon,
]);
}
}
section.component.html
<section ibmRow class="info-section info-section__r1">
<div ibmCol [columnNumbers]="{'md': 4, 'lg': 4}">
<h3 class="info-section__heading">{{heading}}</h3>
</div>
<app-card
ibmCol
[columnNumbers]="{'md': 4, 'lg': 4}"
[heading]="items[0].heading"
[content]="items[0].content"
>
<svg ibmIcon="person--favorite" size="32"></svg>
</app-card>
<app-card
ibmCol
[columnNumbers]="{'md': 4, 'lg': 4}"
[heading]="items[1].heading"
[content]="items[1].content"
>
<svg ibmIcon="application" size="32"></svg>
</app-card>
<app-card
ibmCol
[columnNumbers]="{'md': 4, 'lg': 4}"
[heading]="items[2].heading"
[content]="items[2].content"
>
<svg ibmIcon="globe" size="32"></svg>
</app-card>
</section>
card.component.html
<div class="info-card">
<h4 class="info-card__heading">
{{splitHeading[0]}}
<strong>{{splitHeading[1]}}</strong>
</h4>
<div class="info-card__body">{{content}}</div>
<div class="info-card__icon">
<ng-content></ng-content>
</div>
</div>
How can i solve that ? I don't get any error be it in VS Code or in the browser.
The problem was that I wasn't importing the IconModule in my info.module.ts so obviously it couldn't load the icons.
The corrected file :
info.module.ts
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
// IBM Carbon Modules
import Application32Icon from '#carbon/icons/es/application/32';
import Globe32Icon from '#carbon/icons/es/globe/32';
import PersonFavorite32Icon from '#carbon/icons/es/person--favorite/32';
import { GridModule, IconModule, IconService } from 'carbon-components-angular';
// App Modules
import { CardComponent } from './card/card.component';
import { SectionComponent } from './section/section.component';
#NgModule({
declarations: [
CardComponent,
SectionComponent
],
imports: [
CommonModule,
GridModule,
IconModule
],
providers: [],
exports: [
SectionComponent,
CardComponent
]
})
export class InfoModule {
constructor(protected iconService: IconService) {
iconService.registerAll([
Application32Icon,
Globe32Icon,
PersonFavorite32Icon,
]);
}
}
I have this problem where i made three different components with routing. The problem is when i open my different components they loop twice at the moment i open them. What is causing this and how can i get rid of it?
Heres one example component which console.log runs twice when i open it.
import { Component, OnInit } from '#angular/core';
import nameData from '../../names/names.json'
interface INames {
name: string,
amount: number
}
const { names } = nameData
#Component({
selector: 'app-four',
templateUrl: './four.html',
styleUrls: ["./four.css"]
})
export class FourComponent {
nameArray: Array<INames> = names
constructor() {
}
hasName(nameParam: any) {
console.log("miksi tämä tulee kaksi kertaa")
return this.nameArray.some(elem => elem.name === nameParam)
}
}
And here is the app.module.ts and app-routing.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { OneComponent } from './requirements/one/one';
import { TwoComponent } from './requirements/two/two';
import { ThreeComponent } from './requirements/three/three';
import { FourComponent } from './requirements/four/four';
import { NgbModule } from '#ng-bootstrap/ng-bootstrap';
import { HeaderComponent } from './header/header';
#NgModule({
declarations: [
AppComponent,
OneComponent,
TwoComponent,
ThreeComponent,
FourComponent,
HeaderComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgbModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app-routing-module.ts
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { HomeComponent } from './home/home';
import { FourComponent } from './requirements/four/four';
import { OneComponent } from './requirements/one/one';
import { ThreeComponent } from './requirements/three/three';
import { TwoComponent } from './requirements/two/two';
const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'one', component: OneComponent },
{ path: 'two', component: TwoComponent },
{ path: 'three', component: ThreeComponent },
{ path: 'four', component: FourComponent }
]
#NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
I'm really confused why it loops the function as soon as i press the components button?
I do not recommand at all to use function in the HTML template, because they will be called everytime the Angular's change detection runs. Angular isn't able to tell if the result of the function will be different after each modification, si Angular will call the function everytime something change in the UI.
You must store the result of the function in a variable. Angular can check that the reference of the variable hasn't change.
You can read more information about it on this medium.
I recommend that you do the following
public fullName: string;
constructor() {
this.updateName();
}
private updateName(nameParam: any) {
console.log("miksi tämä tulee kaksi kertaa");
this.fullName = this.nameArray.some(elem => elem.name === nameParam);
}
{{ fullName }}
I am trying to make a library that I can use a component from but angular says that the element I use is not recognized as an element. I am trying to export the VitalSignLinesListComponent.
The steps I follow are:
declare the component in the library module
export the component
in the library module
export the component in the public API
import the module from the library
place the element in the html
file
receive error
The error I am getting:
ERROR in src/app/app.component.html:2:1 - error NG8001:
'lib-vital-sign-lines-list' is not a known element: 1. If
'lib-vital-sign-lines-list' is an Angular component, then verify that
it is part of this module.
2. If 'lib-vital-sign-lines-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component
to suppress this message.
COMPONENT:
#Component({
selector: 'lib-vital-sign-lines-list',
templateUrl: './vital-sign-lines-list.component.html',
styleUrls: ['./vital-sign-lines-list.component.css']
})
export class VitalSignLinesListComponent implements OnInit {
#Input()
idEdDossier: string;
}
LIBRARY MODULE:
import { NgModule } from '#angular/core';
import { VitalsignsComponent } from './vitalsigns.component';
import { BrowserModule } from '#angular/platform-browser';
import { HttpClientModule } from '#angular/common/http';
import { RouterModule, Routes } from '#angular/router';
import { ModalInputComponent } from './modal-input/modal-input.component';
import { VitalSignLinesListComponent } from './vital-sign-lines-list/vital-sign-lines-list.component';
import { NgSelectModule } from '#ng-select/ng-select';
import { FormsModule } from '#angular/forms';
import { EcareLibModule } from 'ecarelib'
import { NgbModule } from '#ng-bootstrap/ng-bootstrap';
import { ComboBoxComponent } from './combo-box/combo-box.component';
import { ComboBoxPipe } from './combo-box/combo-box.pipe';
import { LogService } from './services/log.service';
import { ClickOutsideDirective } from './vital-sign-lines-list/click-outside.directive';
const appRoutes: Routes = [
{ path: 'modal', component: ModalInputComponent },
{ path: 'vitalSignLinesList', component: VitalSignLinesListComponent }
];
// #dynamic
#NgModule({
declarations: [
VitalsignsComponent,
ModalInputComponent,
VitalSignLinesListComponent,
ComboBoxComponent,
ComboBoxPipe,
ClickOutsideDirective
],
imports: [
BrowserModule,
HttpClientModule,
EcareLibModule.forRoot(),
NgSelectModule,
RouterModule.forRoot(appRoutes, { enableTracing: false }),
FormsModule,
NgbModule
],
providers: [LogService],
exports: [VitalsignsComponent, VitalSignLinesListComponent]
})
export class VitalsignsModule {
}
PUBLIC-API:
export * from './lib/vitalsigns.service';
export * from './lib/vitalsigns.component';
export * from './lib/vitalsigns.module';
export * from './lib/vital-sign-lines-list/vital-sign-lines-list.component';
IMPORT LIBRARY: (VitalsignsModule)
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { NgSelectModule } from '#ng-select/ng-select';
import { FormsModule } from '#angular/forms';
import {NgbModule} from '#ng-bootstrap/ng-bootstrap';
import { AppComponent } from './app.component';
import { HttpClientModule } from '#angular/common/http';
import { RouterModule, Routes } from '#angular/router';
import { EcareLibModule } from 'ecarelib';
import { VitalsignsModule } from 'vitalsigns';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
EcareLibModule.forRoot(),
HttpClientModule,
RouterModule.forRoot([]),
VitalsignsModule,
NgbModule,
NgSelectModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
HTML:
<lib-vital-sign-lines-list [idEdDossier]=idDossier></lib-vital-sign-lines-list>
I have created component within module and trying to output the result with simple html code in 'app.component.html'
When I hover on the code it shows me this error "BlogpostModule' is declared but its value is never read.ts(6133)"
When I remove the code "". I see the output.
Please help me to fix this blank page.
app.component.html
<div class="container">
<app-header></app-header>
<app-banner></app-banner>
<app-blogpost-featured></app-blogpost-featured>
<app-footer></app-footer>
</div>
<router-outlet></router-outlet>
app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppRoutingModule } from './app-routing.module';
import { BlogpostModule } from './blogpost/blogpost.module';
import { CmspageModule } from './cmspage/cmspage.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { BannerComponent } from './banner/banner.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
#NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent,
BannerComponent,
PageNotFoundComponent
],
imports: [
BrowserModule,
AppRoutingModule,
CmspageModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
blogpost.module.ts
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { BlogpostRoutingModule } from './blogpost-routing.module';
import { BlogpostFeaturedComponent } from './blogpost-featured/blogpost-featured.component';
import { BlogpostListComponent } from './blogpost-list/blogpost-list.component';
import { BlogpostDetailComponent } from './blogpost-detail/blogpost-detail.component';
import { BlogpostRecentComponent } from './blogpost-recent/blogpost-recent.component';
import { CategoriesComponent } from './categories/categories.component';
#NgModule({
imports: [
CommonModule,
BlogpostRoutingModule
],
exports: [
BlogpostFeaturedComponent
],
declarations: [BlogpostFeaturedComponent, BlogpostListComponent, BlogpostDetailComponent, BlogpostRecentComponent, CategoriesComponent],
})
export class BlogpostModule { }
You forgot to include BlogpostModule in your app.module.ts.
I have a sidebar in my page with certain options, I want to get redirected in a new page when the options are clicked.
I have an option called 'Pricing Details' when I click it a new page should open with /pricing added to the end of the base the URL. Although, the URL is getting updated, the new page is not opening.
This is my app.module.ts
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { PricingComponent } from './pricing/pricing.component';
const routes: Routes = [{ path: 'pricing', component: PricingComponent}];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
This is HTML part with the Pricing Section
<li class="sub-menu" name="idk">
<a routerLink='/pricing'>
<span>Pricing Details</span>
</a>
</li>
This is my app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { NavbarComponent } from './navbar/navbar.component';
import { HomeComponent } from './home/home.component';
import { PricingComponent } from './pricing/pricing.component';
import { EstimateComponent } from './estimate/estimate.component';
import { AccountComponent } from './account/account.component';
#NgModule({
declarations: [
AppComponent,
SidebarComponent,
NavbarComponent,
HomeComponent,
PricingComponent,
EstimateComponent,
AccountComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
When I click on pricing details, the URL is updating, but it's staying on the same page.
Make sure you have included <router-outlet></router-outlet> in AppComponent html template