![]() Here is the code to generate random data. We earlier downloaded the Chance.js package to use with Node.js. We will generate random data on the server side, not on client side, so that we can later demonstrate how to make an HTTP request using Angular 2.Ĭhance.js is available for both client-side and server-side JavaScript. For this, we can use the Chance.js library. To populate our template, we need to generate some random search result data. And finally, is what displays the component based on the current URL. The navigation bar has an anchor tag that doesn't have an href attribute instead, we are using the routerLink directive to assign the redirect link so that when clicked on, instead of a complete page reload, it only changes the URL and component. In the AppComponent template, we are displaying a navigation bar. ![]() ng.router.APP_BASE_ HREF is used to find the base URL of the app. Also, we are providing a custom provider, which returns the / character when an instance of the ng.router.APP_BASE_HREF service is requested. While initializing the app, we're passing the ng.router.ROUTER_PROVIDERS provider, which will be used to create instances of various services related to routing. The ng.router.RouteConfig method returns a function that takes the root component and attaches the routes to it. Here, the first route is for the home page, second for displaying the search result, and finally, the third for handling invalid URLs, that is, URLs for which routes are not defined. ![]() The paths can be static, parameterized, or wildcard, just like Express route paths. A route consists of a path, component, and the name of the route. We are providing an array of routes as an argument to the ng.router.RouteConfig method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |