What I'm attempting to do: I'm building a single-page app using Angular UI-Router. One of my pages has a line chart so I am using angular-chart.js.
What I don't understand: I don't understand how to get the charts to show inside the UI-Router state. I can get the graph to work if I don't include it into a single-page app. I have a feeling I need to add a controller to the UI-Router state containing the $scope labels, series and data, but I haven't been able to get it to work properly.
Angular-Chart.js Code
var chartApp = angular.module('myApp', ['chart.js']);
chartApp.controller("LineCtrl", function ($scope) {
'use strict';
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Motivation', 'Workload'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
});
UI-Router Code
var myApp = angular.module('myApp', ['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider) {
'use strict';
// For any unmatched url, redirect home
$urlRouterProvider.otherwise('/home');
$stateProvider
// chart page
.state('charts', {
url: '/charts',
templateUrl: 'app/charts.html'
});
});