我在 app.js 文件中创建了自定义指令网站。
app.directive('sites',function ($rootScope) {
var siteController =['services','$scope','$rootScope' , function(services,$scope,$rootScope){
// From this function i return promise
$scope.getAllSiteService = function() {
return services.getSiteList($scope.panel.panelConfig.moduleAlias,$scope.searchText,$scope.startSitePosition);
}
$scope.$on('loadsiteonedit',function(args){
return services.getSiteList(args.alias,args.searchText,args.startPosition);
});
}];
return{
restrict : 'E',
controller: siteController,
template : '/site/site.html'
}
});
我的控制器
app.controller('dataVisualisationPanelCtrl', [ '$scope', '$http', '$modalInstance', '$modal', '$log', '$rootScope', 'panel', 'services', 'callfrom', '$q','loadJS',
function($scope, $http, $modalInstance, $modal, $log, $rootScope, panel, services, callfrom, $q,loadJS) {
$scope.onload = function() {
var scopeData ={
"alias" : $scope.panel.panelConfig.module,
"searchText" : '',
"startPosition" : $scope.startSitePosition
}
// Both are used respectively.
$scope.$emit('loadsiteonedit',scopeData );
$scope.$broadcast('loadsiteonedit', scopeData );
}}]);
从自定义指令我需要将promise返回给控制器。我怎样才能做到这一点。 注意:我们使用的是角度1.2