javascript - How to make a component load other components and its related files -
i trying create app using angularjs 1.5, trying architect app, far been fun , interesting.
i have 2 components, 1 of them "chart" , other component "dashboard". chart suppose part of dashboard not sure how embed chart in such way dashboard becomes resposible loading chart , related files template, controller, style sheets etc.
index.html
<html> <head> <style> td{ border: 1px solid black; } </style> </head> <body ng-app="hellosolarsystem"> <a ui-sref="dashboardpage" ui-sref-active="active">dashboard</a> <a ui-sref="about" ui-sref-active="active">about</a> <ui-view></ui-view> <script src="//npmcdn.com/angular@latest/angular.js"></script> <script src="//npmcdn.com/angular-ui-router@1.0.0-alpha.4/release/angular-ui-router.js"></script> <script src="hellosolarsystem.js"></script> <script src="components/about.js"></script> <script src="components/dashboardpage.js"></script> </body> </html>
hellosolarsystem.js
angular.module('hellosolarsystem', ['ui.router']) .config(function($stateprovider) { // array of state definitions var states = [{ name: 'dashboardpage', url: '/dashboardpage', // using component: instead of template: component: 'dashboardpage' }, { name: 'about', url: '/about', component: 'about' } ] // loop on state definitions , register them states.foreach(function(state) { $stateprovider.state(state); }); });
components/mychart.js
angular.module('hellosolarsystem').component('mychart', { templateurl: 'components/mychart.html', })
components/mychart.html
<div> <h3> chart component </h3> </div>
components/dashboardpage.js
angular.module("hellosolarsystem") .component("dashboardpage", { templateurl: 'components/dashboardpage.html', bindings: {}, controller: function($element){ } });
components/dashboardpage.html
<table style="width:100%"> <tr> <td> <!-- show chart --> <mychart></mychart> </td> </tr> <tr> <td> chart component here </td> </tr> </table>
here sample plnkr made demonstrate problem https://plnkr.co/edit/alqtd5azr16hkbwwwon5?p=preview
how dashboard load chart , files ?
the expected outcome hoping
Comments
Post a Comment