检测@ViewChild()中值何时发生变化

时间:2018-05-18 11:21:47

标签: angular typescript angular2-changedetection

我已经获得了一个只是+/-计数器的组件。我可以像这样从这个组件中获取我需要的值:

<sas-plus-minus value="0" min="0" max="99" #adultCount></sas-plus-minus>
{{ adultCount.val }}

adultCount.val显示sas-plus-mins组件中的正确值,但我不知道如何在父组件中观察此值的更改。我很难修改这个子组件的代码,我可能会使用Output()来通知父组件。

如何在我的父组件中为此sas-plus-minus val注册一个wathcer?

1 个答案:

答案 0 :(得分:-1)

你可以把听众放在这个:

//for VIEW based TableViews using Objective C
//in your NSTableViewDelegate, implement the following
//this customization makes the column numbers red if negative.
- (NSView *)tableView:(NSTableView *)inTableView
   viewForTableColumn:(NSTableColumn *)tableColumn
                  row:(NSInteger)row
{
    NSTableCellView *result = nil;
    if ([tableColumn.title isEqualToString: @"Amount"]) {
        //pick one of the following methods to identify the NSTableCellView
        //in .xib file creation, leave identifier "blank" (default)
         result = [inTableView makeViewWithIdentifier:[tableColumn identifier] owner:self];
        //or set the Amount column's NSTableCellView's identifier to "Amount"
        result = [inTableView makeViewWithIdentifier:@"Amount" owner:self];
        id aRecord = [[arrayController arrangedObjects] objectAtIndex:row];
        //test the relevant field's value
        if ( aRecord.amount < 0.0 )
            [[result textField] setTextColor:[NSColor colorWithSRGBRed:1.0 green:0.0 blue:0.0 alpha:1.0]];
    } else {
        //allow the defaults to handle the rest of the columns
        result = [inTableView makeViewWithIdentifier:[tableColumn identifier] owner:self];
    }
    return result;
}

如果(更改)不起作用(ngModelChange)。在您的.ts文件中:

<sas-plus-minus (change)="detect($event)" value="0" min="0" max="99" #adultCount [(ngModel)]="adultCount"></sas-plus-minus>

你可以从事件中获取价值。