我有这样的指令
ng-repeat="place in tb_places | filter:{'id':inputID}"
Run Code Online (Sandbox Code Playgroud)
输出一些对象数组看起来像这样
$scope.tb_places = [
{name: 'some1', id:1}
...
{name: 'some10', id:10}
{name: 'some11', id:11}
{name: 'some12', id:12}
...
]
Run Code Online (Sandbox Code Playgroud)
当我更改inputID并将其设置为1时,结果数组将填充源数组的元素,其中'ids'为1和10,11,12.因此,'id'值的部分被检查为子串,而不是数字.我该怎样治愈它?
谢谢!
UPD我试图在过滤器表达式中添加":true" - 它完全清除输出(结果数组),它适用于一个简单的字符串数组,但不适用于对象("true"想要与模式对象完全匹配,这意味着及其所有属性)
解决了!!!
对不起伙计们,我的错!'inputID'与'id'(string vs int)的类型不同,因此内置比较器(":true")返回false.非常感谢!
抱歉,我不能为你投票答案 - 缺乏声誉......见到你!
我相信,使用lodash写一个更短的方法(一行):
_.forEach(eventListeners, function(callback) {
callback(event);
})
Run Code Online (Sandbox Code Playgroud)
......但还找不到
我有几个带有“工具”的组件,并在创建时将这些工具插入应用程序中预定义的“命名”位置,例如左/右/侧工具栏。他们使用 Angular CDK Portals 来做到这一点。它看起来像这样:
// component template here...
// then portions of UI for portals, like this:
<ng-template cdkPortal #leftToolbar>
<app-search-input #search (search)="onSearch($event)"></app-search-input>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
app-search-input我的目标是以某种方式获取对放置在门户内的组件的引用。
如下所示不起作用,this.searchEl始终是undefined:
// component class
@ViewChild('search', {static: true}) searchEl: SearchInputComponent;
Run Code Online (Sandbox Code Playgroud)
伙计们有什么想法吗?