は、いくつかの試行錯誤の後、私は、各コンポーネントのレンダリング時間を計算する方法(divを)見つけ
HTML:
<div ng-controller="Controller1">
<div custom-performance="log1" content="Content1">{{log1}}</div>
</div>
<div ng-controller="Controller2">
<div custom-performance="log2" content="Content2">{{log2}}</div>
</div>
角度:
'use strict';
var app = angular.module('myApp', []);
app.controller('Controller1', ['$scope', '$http', function($scope, $http) {
$http({
method: 'POST',
url: 'JSON/catlog.json'
}).success(function(response) {
$scope.log1 = response;
}).error(function(error) {
});
}]);
app.controller('Controller2', ['$scope', function($scope) {
$scope.log2 = "Hello World";
}]);
app.directive('customPerformance', ['$rootScope', function($rootScope) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$rootScope.graphOutput = [];
var start = new Date();
var endTime = null;
scope.$watch(attrs.customPerformance, function(newval) {
if (newval != undefined) {
setTimeout(function() {
endTime = (new Date() - start);
$rootScope.graphOutput.push({
'content': attrs.content,
'timeTaken': endTime
});
console.log(JSON.stringify($rootScope.graphOutput));
});
}
});
}
}
}]);