我有一个元素指令,我想知道是否可以从routeProvider获取参数以呈现模板并在控制器中进行设置。

adminDash.directive('hospitals', function() {
    return {
        restrict: 'E',
        templateUrl: 'www/partials/admin/hospitals.html',
        controller: 'AdminHospitalsController',
        controllerAs: 'hospitalsCtrl',
    };
});


如何在我的element指令中获取任何参数?

最佳答案

您可以像下面这样隔离指令的范围:

adminDash.directive('hospitals', function() {
    return {
        restrict: 'E',
        templateUrl: 'www/partials/admin/hospitals.html',
        controller: 'AdminHospitalsController',
        controllerAs: 'hospitalsCtrl',
        scope: {
            paramValue: '&',
            paramVariable: '=',
        },
    };
});


检查此内容以更好地了解https://thinkster.io/egghead/isolate-scope-am/

关于javascript - 从element指令中的routeProvider获取参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27027997/

10-12 12:56
查看更多