javascript - How to rename multiple services in Angualr Js? -


the code base , working build upon angularjs 1.4.6.i have migrated angular 1.5.11 , result angular-ui needs upgraded well. when upgrading angularui bootstrap version 0.14.3, breaking changes renaming of prefixes. earlier $modal & $modalinstance $uibmodal & $uibmodalinstance.

the earlier syntax using service in controller :

angular.module('main').controller('mainctrl',function($scope,$modal...) {  $scope.open  = function() {         var modalinstance = $modal.open({             templateurl: 'modal.html',             controller: 'modalctrl',             size : 'md',             resolver : {                 data: function() {                     return $scope.items;                 }             }         })         modalinstance.result.then(function() {}, function () {});     }     }); angular.module('main').controller('modalctrl',function($scope,$modalinstance,data) { console.log(data); }); 

now $modal , $modalinstance both deprecated since service used in on 50+ controllers , called many times. thought rename service instead of changing it.

here's did:

.factory('$modal',function($uibmodal){ return $uibmodal; }); 

and inject required controller:

angular.module('main',function($scope,$modal...) { /** }); 

now deprication warning not coming $modal when did same $modalinstance warning coming. deprecation warning here's code implemented:

.factory('$modalinstance',function($uibmodalinstance){ return $uibmodalinstance; }); 

so how can solve this? need on 20 other services have prefixes changed. do, need create 20 factory methods or can done in way?

this not in long term when can confused used. can raise unstable result when factory same named $modalinstance (this factory still exist in angularui see in warning message).

i prefer simple solution "find & replace", 1 time , never have think again :).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -