I am trying to create an app using angularJs 1.5, currently trying to properly architect my app, so far its been very fun and interesting.
I have two components, one of them is for a "chart" and the other component is a "dashboard". The chart is suppose to be a part of the dashboard but I am not sure how to embed chart in such a way that the dashboard becomes resposible for loading the chart and its related files like 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) {
// An array of state definitions
var states = [{
name: 'dashboardPage',
url: '/dashboardPage',
// Using component: instead of template:
component: 'dashboardPage'
},
{
name: 'about',
url: '/about',
component: 'about'
}
]
// Loop over the state definitions and 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> This is my 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>
<!-- this is where I will show my chart -->
<mychart></mychart>
</td>
</tr>
<tr>
<td> Another chart component will be here </td>
</tr>
</table>
Here is a sample plnkr made to demonstrate my problem https://plnkr.co/edit/alQtd5azr16hKbwwWoN5?p=preview
How do I get dashboard to load chart and its files ?
The expected outcome I am hoping for is