Multiple Components in angular2
NickName:SelvaKumar Selvi Ask DateTime:2016-11-18T21:16:07

Multiple Components in angular2

I'm new to angular 2 , In multiple components i have written a two components in a single folder file i have import the 2nd class in first file and given directive: class but its showing error! Here the app.module.ts file

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
@NgModule({
    imports:      [ BrowserModule ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
 })
export class AppModule { }

Here the first component file app.component.ts

import { Component } from '@angular/core';
import { mydetailsComponent } from './app.details';

@Component({
   selector: 'my-app',
   template: `<h1>Welcome to this Application...</h1>
   <p>We have the App details here:</p>
   <mydetails></mydetails>
   `
  directives: [ mydetailsComponent ] })
export class myAppComponent { }

Here second Component file app.details.ts

import { Component } from '@angular/core';
@Component({
  selector: 'mydetails',
  template: `<ul>
             <li>Settings</li>
             <li>Profile</li>
             <li>Games</li>
             <li>Gallery</li>
            `
})
export class mydetailsComponent { }

Please tell us how to use and display the multiple components!

Copyright Notice:Content Author:「SelvaKumar Selvi」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40678088/multiple-components-in-angular2

More about “Multiple Components in angular2” related questions

Insert different Angular2 components programmatically

I want to programmatically generate a report composed by multiple distinct components from a JSON file like: { components: [UserStatsComponent, ActivityChartComponent, NetworkGraphComponent] }...

Show Detail

Communication between nested multiple components in Angular2

I am doing an Angular2 project with nested multiple component. I managed to send some data from immediate child component to immediate parent component. But in case of 3 nested component, how can I

Show Detail

Angular2 : How to have the same guard for multiple components

In Angular2, is it possible to have the same guard (for exemple CanActivate or CanDeactivate) which can be applied to multiple components ? Here is a guard for MyComponent1 : @Injectable() export...

Show Detail

Insert angular2 components in Svg

I recently started web dev. and angular2 in particular. I must say that this framework is fantastic! But I have one challenge that I cant figure out how to solve in the best way: I want to build ...

Show Detail

angular2 nested components

I have multiple components, each one has its own view template (angular2 alpha 46) PostCmp CommentCmp ShareCmp I want to load them from a main component and display them in its own view template

Show Detail

How to render multiple angular2 components in one page?

I am working on this project in which I have to load multiple components in one page. my directory structure is like this: I have created few components in angular2 previously. I can render all

Show Detail

Sharing an observable between components / multicast an observable in Angular2

Learning observable and Angular2. I want to find out the BEST practices of sharing an observable between multiple Angular2 components. As observable default is NOT multicast. So each subscription in

Show Detail

How to pass in variables to modules and components in angular2

I am using angular2 to boostrap multiple UI modules if my webpage has the component selectors. I can't use a main app element and put all my content inside it. I want to however pass in variables t...

Show Detail

Can AngularJS Material Components work with Angular2?

I just received a web app project from a co-worker who left our company. The project was built using Angular2 as its framework but it appears as though this worker tried to use AngularJS Material f...

Show Detail

nested Components in angular2

I'm going to upgrade my knowledge of angular2 from version Rc5 to 2.2. I have problem with directive property that had been deprecated since i upgraded my packages.I know it moves to imports proper...

Show Detail