1 angular.module('iManager.directive', []).directive('resize', function ($window) {
2 return function (scope, element) {
3 //获取标签的id属性值
4 var id = element[0].id;
5 var w = angular.element($window);
6 scope.getWindowDimensions = function () {
7 return {
8 'h': w.height(),
9 'w': w.width()
10 };
11 };
12 scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
13 //获取新窗口的宽度和高度
14 scope.windowHeight = newValue.h;
15 scope.windowWidth = newValue.w;
16 //获取容器,重新绘图
17 var ele = document.getElementById(id);
18 var pieChart = echarts.init(ele);
19 pieChart.resize();
20 }, true);
21 w.bind('resize', function () {
22 //页面脏检查
23 scope.$apply();
24 });
25 }
26 })
1 /** app.js文件 **/
2 var iManager=angular.module("iManager",['iManager.directive'])
3 /*备注:模块声明,模块名:iManager,在[]里面依赖注入相关模块*/