how to create wrapper directives for Controller in AngularJS

怎甘沉沦 提交于 2019-12-20 05:49:30

问题


I'm trying to do upgrade controllers/components written in AngularJS1 to Angular6. I'm taking the approach of having the wrappers for all the existing AngularJS1 controllers/component by extending "UpgradeComponent" placed under the folder "directive-wrappers" in my example.

We have many controllers written in AngularJS1 which need to upgraded and used inside Angular6 application. Since these controllers are bit complex we don't want to rewrite it or touch these controllers, instead we want to create some directives which would be like a wrappers for these controllers and eventually upgraded and used. I'm bit stuck here on how to write the directives for the existing controllers?

I have created the POC, in which I wanted to upgrade homepageController and UserServiceController. These 2 controllers to be wrapped in a directive and then upgraded to Angular6.

The typical existing controllers would look like this, since it is bit complex and contains many functionalities we don't want to touch these existing controllers.

hence create a wrapper directives for these...

angular.module('app.products').controller('ProductDetailsController', [

    '$scope', 'restService', 'currentCartService', 'productDetailsDialogService', 'constants', 'dialog', '$state', 'checkValues', 'rightsService', 'addSkuToItemsDialogService',
    'dsaContextService', 'dfsService','messenger','cartExtService','dfsDpaExtService', 'dfsSmbExtService',
    function($scope, restService, currentCartService, productDetailsDialogService, constants, dialog, $state, checkValues, rightsService, addSkuToItemsDialogService,
        dsaContextService, dfsService, messenger, cartExtService, dfsDpaExtService, dfsSmbExtService) {

        'use strict';

        $scope.iAm = 'ProductDetailsController';

         $scope.addItemToCart = function() {
         ...
          };

        $scope.isCartActive = function() {
            ...
        };
        ...           
        ...
 }]);

来源:https://stackoverflow.com/questions/58468481/how-to-create-wrapper-directives-for-controller-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!