例如;
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>
答案 0 :(得分:1)
要解决 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);