AngularJs - 控制器和指令之间的通信

AngularJs - communication between controller and directive

例如;

GetSwatchCartListFunc:如何直接从指令访问此方法

homeController.js

(function (App) {
    var Home = function Home($scope, MemberService) {


        $scope.GetSwatchCartListFunc = function (patternDetailLineId) {
            MemberService.GetSwatchCartList(patternDetailLineId).then(function (res) {
                console.log(res.data);
                if (res.data.status === ServiceResulState.Success) {
                    $scope.SwatchCartListData = res.data.resultList;
                    $('#swathcartList').modal('show');
                } else if (res.data.status === ServiceResulState.Fail) {
                    toastr.warning(res.data.message);
                    $('#userLoginModal').modal('show');
                }
            });
        };


    };

    Home.$inject = ["$scope", "MemberService"];

    App.controller("HomeController", Home);
})(App);

directive.js

(function (App) {
App.directive("ngPatternPre", ['toastr', function (toastr) {
    return {
        restrict: 'E',
        templateUrl: '/views/Directives/NgPattern.html'    
        }
    };
}]);})(App);

NgPattern.html

<a ng-click="SwatchCartList(pId)" title="Add"><i class="ti-Line-Gallery"></i></a>

需要进行以下更改才能解决 directive.js

中的问题

directive.js

(function (App) {
App.directive("ngPatternPre", ['toastr', function (toastr) {
    return {
        restrict: 'E',
        templateUrl: '/views/Directives/NgPattern.html',
        link: function (scope, element, attrs) {                

            scope.SwatchCartList = function (pId) {
                scope.GetSwatchCartListFunc(pId);                   
            };

        }
    };
}]);})(App);