プロジェクトで角度とグラファナを使用しています。私はservice
->を持っていますdashboardViewStateSrv
私のサービスコード:
define([
'angular',
'lodash',
'jquery',
],
function (angular, _, $) {
'use strict';
var module = angular.module('grafana.services');
module.factory('dashboardViewStateSrv', function($location, $timeout) {
function DashboardViewState($scope) {
var self = this;
self.state = {};
self.panelScopes = [];
self.$scope = $scope;
// something
}
return {
create: function($scope) {
return new DashboardViewState($scope);
}
};
});
});
私のサイドメニューコントローラーで:
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
if ($scope.dashboardViewState) {
if($scope.dashboardViewState.state.citreedepth){
depth = +$scope.dashboardViewState.state.citreedepth;
}
}
マイ ダッシュボード コントローラーで:
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
DashboardViewState
オブジェクトが 2 回作成されています (ダッシュボード Ctrl とサイド メニュー Ctrl)。オブジェクトを2回作成してDashboardViewState
いますが、それを避けたいです。DashboardViewState
サイド メニュー ctrl でオブジェクトを作成しないようにするにはどうすればよいですか?
ビュー ステートは 1 つだけである必要があります。私の理解によると、すべてのサービスはAngularのシングルトンです。
私に何ができるか教えてください。