Creating route components

Let's create HomeComponent, SearchResultComponent, and NotFoundComponent. Before that, let's create a component to display the search form. The search form will have a textbox and a search button. Follow these steps:

  1. Place this code in the index.js file, above the AppComponent code:
    var FormComponent = ng.core.Component({
      selector: "search-form",
      directives: [ng.router.ROUTER_DIRECTIVES],  
      templateUrl: "componentTemplates/search-form.html",
    }).Class({
      constructor: function(){},
      ngOnInit: function(){
        this.searchParams = {
          query: ""
        };
    
        this.keyup = function(e){
          this.searchParams = {
            query: e.srcElement.value
          };
        };
      }
    })
  2. Now, create a file named search-form.html in the componentTemplates directory, and place this code in it: ...

Get JavaScript: Moving to ES2015 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.