0

我为错误,警告开发了常见的警报模式,并使用角度基础模式确认。我的问题是,我不能将变量传递给模态。模态内容:

 <h3 class="caps">{{ alertmessage }}</h3>
   <p>{{ alertdetail }}</p>

开放警报服务:

appCommonServiceModule.factory('AlertModalService' , function($modal ,$rootScope){
       function AlertModalService(){
           this.openAlertModal = function($scope,type ,message , detail , successCallback ,cancelCallback ){
               var  templateUrl = ASSETS_PATH+'app/pages/templates/alert/';
               var  className = "reveal-modal small alert-modal ";
               if(type == "SUCCESS"){
                   templateUrl = templateUrl+"success.html";
                   className += "success-modal"
               }
                   $scope.message = message;
                   $scope.detail = detail;
                     var modalInstance  = $modal.open({
                         templateUrl : templateUrl,
                         controller : 'AlertBaseController',
                         backdrop: 'static',
                         windowClass:className,
                         scope:$scope,
                         resolve : {
                             alertmessage: function(){
                                 return $scope.message;
                             },
                             alertdetail :function(){ return $scope.detail; 
                     }
                         }
                     });
                     modalInstance.result.then(function(){
                          if(successCallback){
                              successCallback();
                          }
                     },function(){
                          if(cancelCallback){
                              cancelCallback();
                          }
                     });
           }
       }
       return  new AlertModalService();
    });

我找不到解决方案。
感谢您的帮助

4

1 回答 1

0

首先,您的工厂需要定义类似接口的东西才能与控制器共享其数据:

appCommonServiceModule.factory('AlertModalService' , function($modal, $rootScope) { 
   // [...] your code

   service = {
      getModalData: getModalData
   };
   return service;

   function getModalData() {
      var modalData = {};
      modalData.message = message;
      modalData.detail = detail;
      return modalData;
   }

   // [...] your code
});

其次,您需要控制器在 HTML 中显示数据。您已经定义了一个(controller: 'AlertBaseController'在您的代码中),因此您可以使用它:

appCommonServiceModule.controller('AlertBaseController',  function(AlertModalService, $scope) {
   var modalData = AlertModalService.getModalData();
   $scope.alertmessage = modalData.message;
   $scope.alertdetail = modalData.detail;
});

现在您可以在 HTML 中使用它:

<div ng-app="appCommonServiceModule">
   <div ng-controller="AlertBaseController">
      <h3 class="caps">{{alertmessage}}</h3>
      <p>{{alertdetail}}</p>
   </div>
</div>

我没有测试它,因为我没有完整的代码,但是这样的东西应该可以工作。

于 2015-03-20T16:48:56.140 回答