我正在尝试过滤使用ng-repeat的dom中的数组.当我对返回进行硬编码时,过滤器有效,但是当我尝试使用它时,它会给我错误
Cannot read property minHeight of undefined.
因此,由于某些原因,这是未定义的,但它适用于控制器中的其他功能.我不确定为什么它在过滤器中不起作用.
我确定我错过了一些非常简单的东西,但我找不到它
调节器
export class ItemComponent { /*@ngInject*/ constructor($http) { this.$http = $http; this.minHeight = 0; } filter(row){ console.log(this.minHeight); return row.minHeight > this.minHeight; }
HTML
ng-repeat="item in itemCtrl.items | filter: itemCtrl.filter"
透明代码(来自浏览器中的app.bundle.js)
var ItemsComponent = exports.ItemsComponent = function () { /*@ngInject*/ ItemsComponent.$inject = ['$http']; function ItemsComponent($http) { _classCallCheck(this,ItemsComponent); this.$http = $http; this.minHeight = 0; } _createClass(ItemsComponent,[{ key: '$onInit',value: function $onInit() { this.loadItems(); } },{ key: 'loaditems',value: function loadItems() { var _this = this; this.$http.get('/api/items').then(function (res) { _this.items = res.data; console.log(_this.items); }).catch(function (err) { console.log(err); }); } },{ key: 'filter',value: function filter(row) { console.log(this.minHeight); return row.minHeight > 3; } }]); return ItemsComponent; }();