Setter @Input binding not working after upgrading to 2.2.3 from 2.1.2
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior In a component class
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
@Component({
selector: 'navigation-sections',
template: require('./navigation-sections.template.html'),
styles: [
require('./navigation-sections.style.scss')
]
})
export class NavigationSectionsComponent implements OnInit {
@Input() sections:Array<string>;
private _selectedSection: number;
@Output() onSelectSection = new EventEmitter<number>();
constructor () {}
ngOnInit(): void {
if (!this._selectedSection) {
this._selectedSection = 0;
}
}
get selectedSection():number{
return this._selectedSection;
}
@Input("selectedSection")
set selectedSection(value:number){
console.log("Setter called");
this._selectedSection=value;
}
selectNavigationSection(value:number,event): void{
if (event.currentTarget.classList.contains('complete')) {
this.onSelectSection.emit(value);
this._selectedSection = value;
}
}
}
after using the component like this:
<navigation-sections [sections]="sections"
[selectedSection]="selectedSection"
(onSelectSection)="onSelectSection($event)">
</navigation-sections>
following error is thrown:
error_handler.js:48 EXCEPTION: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'selectedSection' since it isn't a known property of 'navigation-sections'.
1. If 'navigation-sections' is an Angular component and it has 'selectedSection' input, then verify that it is part of this module.
2. If 'navigation-sections' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.
("
<div class="col-xs-12">
<navigation-sections [sections]="sections"
[ERROR ->][selectedSection]="selectedSection"
(onSelectSection)="onSelectSection($event)">
</naviga"): GlobalHomeTherapiesComponent@3:8
If i use the @Input
annotation directly on the property (the component class looks as follows), then there is no error and property is bound successfully:
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
@Component({
selector: 'navigation-sections',
template: require('./navigation-sections.template.html'),
styles: [
require('./navigation-sections.style.scss')
]
})
export class NavigationSectionsComponent implements OnInit {
@Input() sections:Array<string>;
private _selectedSection: number;
@Input()
private selectedSection:number = 0;
@Output() onSelectSection = new EventEmitter<number>();
constructor () {}
ngOnInit(): void {
if (!this._selectedSection) {
this._selectedSection = 0;
}
}
selectNavigationSection(value:number,event): void{
if (event.currentTarget.classList.contains('complete')) {
this.onSelectSection.emit(value);
this._selectedSection = value;
}
}
}
Expected behavior
Setter @Input
binding should work as per https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-child-setter
Minimal reproduction of the problem with instructions http://plnkr.co/edit/icPStVKWyT4cNSHxYvU3?p=preview
Please tell us about your environment:
-
OS: Win10
-
Package manager yarn, npm
-
Angular version: 2.2.3
-
Browser: all
-
Language: TypeScript 2.1.1
-
Node (for AoT issues):
node --version
= 4.4.2
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Angular2: Input setter not picking up set event if value does ...
I see two ways to solve it: 1) Use immutable value setTimeout(() => { this.name = new String("a"); setTimeout(() => { this.name =...
Read more >Release Notes for Cisco DNA Center, Release 2.2.3.x
To work around this problem, manually upgrade the IPv6 applications from the CLI to the expected release before upgrading the network-visibility ...
Read more >Why Angular Input Setter is Only Being Fired Once
It only updates binding when the value actually changes. As shown above, the Angular Input setter is designed to ignore the binding update...
Read more >Release Notes — Airflow Documentation
The FAB 4.* upgrades a number of dependencies to major releases, which upgrades them to versions that have a number of security issues...
Read more >Spring Boot Reference Documentation
If you find problems with the docs or if you want to improve them, ... empty constructor and getters and setters are usually...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@zoechi decorators just attach metadata to a property with the given name so it doesn’t really matter setter or getter
also
Input
should be on the first propery occurance