2016-11-28 23 views
0

親コントローラ(基本コントローラ)と子コントローラの2つのコントローラがありますが、親コントローラのすべての機能が親コントローラと同じであるため、親コントローラ全体を子コントローラに継承しています。 20台のコントローラ。 これまでの継承は問題ありません。角型コントローラ継承とパッシングパラメータ

私が達成しようとしている何

すべてのコントローラに変え続けるでのSourceURLを持つ親コントローラ内のサーバ機能があり、親コントローラが継承されたときに変更する必要がある唯一の事のthats要求が行われます。今私は親のコントローラでsourceURLを上書きする方法を知らない。私は工場や何かを使わなければならないと思う。誰でも助けてくれますか?

親コントローラー:

WL_module.controller('WLbaseController', WLbaseController); 
    function WLbaseController($scope, $http, $filter, $q, $compile, DTOptionsBuilder, DTColumnBuilder, SimpleHttpRequest, serverData) 
    { 
     $scope.GetTData = function() 
     { 
      $scope.dtOptions = DTOptionsBuilder 
      .newOptions() // make sure to comment it out when working with client side 
      .withFnServerData(server) // for server request 
      .withDataProp('data') 
      .withOption('processing', true) 
      .withOption('serverSide', true) 
      .withOption('stateSave', true) // works only with server side 
      .withOption('responsive', true) // not sure if work with both 
      .withOption('paging', true) 
      .withOption('lengthMenu', [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 100 ]) 
      .withOption('order', [0, 'asc']) 
      .withDisplayLength(10) 
      .withPaginationType('full_numbers') 
      .withButtons([ 
       'colvis', 
       'print', 
       'excel' 
      ]) 
      // .withDOM('frtip') 
      .withOption('createdRow', function(row, data, dataIndex) 
      { 
       $compile(angular.element(row).contents())($scope); 
      }); 
     }; 

     function server(sSource, aoData, fnCallback, oSettings) 
     { 
      // Server Request URL 
      var sourceUrl = _config.furl+'SelectWL/es_wl_1_11_test';   
      return serverData.request($scope, sourceUrl, sSource, aoData, fnCallback, oSettings); 
     } 

     // Always Initialize it to Render the Tables 
     $scope.GetTData(); 
    }; 

子供コントローラー:

​​
+0

サービスを使用して継承を試しましたが、A_serviceを使用してA_serviceを使用し、B_controllerはA_serviceを拡張するB_serviceを使用しました。子サービスでオーバーライドされる変数urlを使用します。 B_serviceを使用する場所では、オーバーライドされたURLを取得します(この値はコントローラaswelから設定できます)。 – jos

+0

あなたはまた、私はどこかにstackoverflowで角度の継承での拡張を使用してコピーを作るので、良いアイデアではないと読んでいくつかの例を与えることができます。データを混在させることができます。 – Wcan

答えて

0

あなたは、コントローラを使用するよりもサービスを使用して継承を作成することができます。私はサンプルコードを追加しました。

angular.module('app',[]) 
.service('aService', ['someDependency', function(someDependency){ 
    this.url = 'a/url'; 
}]) 
.service('bService', ['aService', function(aService){ 
    //you can create a object using aService and return that from service - use this approach when using a factory 
    //var bService = Object.create(aService); 
    //return bService 
    angular.extend(this, aService); 
    this.url = 'b/url'; 
}]) 
.controller('aCtrl',['$scope','aService', function($scope, aService){ 
aService.url //gives you 'a/url' 
}]) 
.controller('bCtrl',['$scope','bService', function($scope, bService){ 
bService.url //gives you 'b/url'; 
}])