我有此指令
@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还是有其他更好的方法?