通过Angular ngRoute加载图表不起作用
Loading chart via Angular ngRoute not working
我试图通过angular
ngRoute
加载图表(highcharts库),但我无法显示图表。
JS -这是我的配置
var app = angular.module('myApp', [
'ngRoute'
]);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'some.html',
controller: 'MainCtrl'
})
.when('/contacts/:_id', {
templateUrl: 'contacts/some.html',
controller: 'SecondCtrl'
})
.otherwise({
redirectTo: '/'
});
});
JS -这些是我的控制器
app.controller('MainCtrl', ['$scope', function($scope) {
// some code here
}]);
app.controller('SecondCtrl', ['$scope', function($scope) {
//some code here
// drawing chart function
$(function () {
$('#container').highcharts({
//rest of the code
}]);
HTML//联系人/some.html页
控制台没有错误,尽管图表没有加载
加载在主页- index.html只有当写入
<div ng-controller="SecondCtrl">
<div id="container"></div>
</div>
你可以尝试创建一个指令"chart",并在link函数中使用$element来初始化Highchart对象。如下所示:
app.directive("chart", function () {
return {
template: '<div id="chartContainer" style="height: 500px; min-width: 310px; max-width: 1024px; margin: 0 auto"></div>',
restrict: 'E',
scope: {
data: "=" // two way binding
},
replace: true,
controller: 'CustomCtrl',
link: function ($scope, element, $attrs) {
var mapChart = $(element).highcharts('Area', {
chart: {
renderTo: $(element).attr('id')
},series: [
{
name: 'Countries',
mapData: mapData,
color: '#E0E0E0',
enableMouseTracking: false
},/* so on */
在你的html页面下添加
<div class="container" ng-controller="CustomCtrlas customCtrl">
<chart class="container" data='customCtrl.chartData'>
</div>
如果有帮助请告诉我
相关文章:
- JavaScript链接在点击时不起作用;函数在页面加载时工作
- Jquery(多读/少读)在从数据库加载整个数据后不起作用
- 加载后的页面与ajax表单提交不起作用
- jQuery加载完成事件不起作用
- $(select).selectmenu('打开')不'如果使用ajax加载页面,则不起作用
- 使用requireJS的jqGrid-网格加载但不起作用
- 加载自定义类在ExtJs中不起作用
- jQuery Mobile pageinit在第一次加载页面上不起作用(可复制)
- jquery ias插件不适用于我的网站,加载更多项目不起作用
- getUserMedia()在使用Ajax加载时不起作用
- 同一页面上的 mysql 中的 Ajax 加载表不起作用
- 按钮在第一次成功的 ajax 数据加载后不起作用
- 谷歌将部分页面加载后自动完成不起作用 ASP.Net MVC
- 使用 jQuery .load() 加载的内容不起作用
- HTML 不加载 CSS ,刷新后一切正常.同样在移动设备上,它在首次加载时不起作用
- ng-view 中的脚本在从文件引用时不起作用(JQuery 在角度之前加载)
- JavaScript 图像加载器不起作用
- 淡出加载然后淡入不起作用
- 使用 jquery 在我的网站中加载其他网页不起作用
- 在加载javascript之前让页面加载的代码不起作用