У меня есть эта директива
@am.directive 'modalTabSiteSheet', ( $rootScope,
AMDataStore, Geocoder, Media ) ->
restrict: 'E'
replace: true
templateUrl: 'templates/modal/site/_sheet.html'
controller: ( $scope ) ->
DATASTORE_CACHE_KEY = 'modalTabSiteSheet'
dataStore = AMDataStore.getInstance()
$scope.calculateDistance = ->
dataStore.get DATASTORE_CACHE_KEY, "/sites/#{$scope.site.id}/distances", {}, (data) ->
$scope.distances = JSON.parse(data.distances)
console.log $scope.distances
$scope.calculateDistance()
и я хочу вызвать $ scope.calculateDistance () из другого контроллера:
@am.controller 'ModalSiteController', ( $scope, $uibModalInstance, $translate, $routeParams,
AMDataStore, GetModal,
site ) ->
DATASTORE_CACHE_KEY = 'ModalSiteController'
dataStore = AMDataStore.getInstance()
$scope.site = site
$scope.input =
isEditModeEnabled: false
unless $scope.site.radius
dataStore.get DATASTORE_CACHE_KEY, "/settings", {}, (data) ->
$scope.site.radius = _( data.settings() ).findWhere( key: "default_radius" ).formattedValue()
if $scope.site.isNewRecord()
$scope.site.company_id = $scope.currentCompany.id
$scope.site.address_id = dataStore.addresses.add().id
$scope.isNewRecord = true
$scope.input.isEditModeEnabled = true
$scope.$watch 'site', ( site ) ->
if site
$scope.buttonAction =
label: $translate.instant( 'btn.save' )
disabled: true
$scope.$watch 'site.name', ( name ) ->
$scope.buttonAction.enabled = name?
**$scope.save = ->
$scope.site.saveWithChildren()**
метод должен вызываться в действии $ scope.save. Должен ли я использовать $ rootScope или есть какой-то другой способ лучше?