我需要一些帮助,我认为必须是一个愚蠢的错误。这是我正在使用的代码但是this.area_id和this.location_id是未定义的。我错过了什么?
HTML
<location-search area_id="1" location_id='376'>
</location-search>
JS
class locSearchController {
constructor(Search, $state) {
this.$state = $state;
this.Search = Search;
debugger;
this.params = {};
this.params.area_id = this.area_id;
this.params.location_id = this.location_id;
}
}
var locationSearch = function() {
return {
bindToController: {
area_id: '@',
location_id: '@'
},
scope: {
},
controller: locSearchController,
templateUrl: 'frontpage/location.dir.html',
controllerAs: 'vm'
}
}
angular.module('app')
.directive('locationSearch', locationSearch);
答案 0 :(得分:3)
Angular将指令属性名称规范化为camelCased版本。尝试:
bindToController: {
areaId: '@',
locationId: '@'
}
并且,在控制器中访问:
this.areaId;
this.locationId;