我有一个元素指令,我想知道是否可以从routeProvider获取参数来渲染我的模板并将其设置在我的 Controller 中。
adminDash.directive('hospitals', function() {
return {
restrict: 'E',
templateUrl: 'www/partials/admin/hospitals.html',
controller: 'AdminHospitalsController',
controllerAs: 'hospitalsCtrl',
};
});
如何获取元素指令中的任何参数?
最佳答案
您可以隔离指令的范围,如下所示:
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/