0

I am trying to use a shared html in the basic angular4 page, i want to use a tag

  <search-items (search)="filter($event,'q')"></search-items> 

which should display a text box of search option.

this is the code iam trying

what should i do to remove my errors?

4
  • what errors are you getting please specify them Commented Jun 28, 2017 at 5:16
  • you can run the given link, use console window to show the errors Commented Jun 28, 2017 at 5:19
  • alot of things were missing , i am able to remove the error . Will post the answer now Commented Jun 28, 2017 at 5:25
  • i am just learning things Commented Jun 28, 2017 at 5:27

2 Answers 2

3

Try this code yourself : This is your app.ts

//our root app component
 import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {SearchComponent} from 'search.ts'
import {FormsModule } from '@angular/forms'
 @Component({
 selector: 'my-app',
 template: '
 <div>
  <h2>Hello {{name}}</h2>
  <search-items (search)="filter($event,'q')"></search-items> 
     </div>',
 declare:[SearchComponent]
})
 export class App {
 name:string;
 constructor() {
 this.name = `Angular! v${VERSION.full}`
 }
 filter(text:string,text2:string){
  console.log("hi")
}
}
 @NgModule({
imports: [ BrowserModule , FormsModule],
declarations: [ App , SearchComponent ],
bootstrap: [ App ]
})

 export class AppModule {}

2nd fix was in search.ts : your search.html was misspelled as search.component.html

Note : Do import FormsModule from @angular/forms whenever you use ngModel in your code

Sign up to request clarification or add additional context in comments.

4 Comments

there is one issue, try entering something and click button and check console.log. after that enter something and click enter. chack console again, you can see function is triggering twice in second case.
Are you sure ?Because i did exactly as u told and it still fires only once . Can you please debug more and give some more info so that i can help you ?
did you check the console.log?
1

In addition to Aakash Uniyal's answer here is the new plnkr with the issue resolved.

You also needed to import FormsModule

`import { FormsModule } from '@angular/forms'`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.