Skip to content

Instantly share code, notes, and snippets.

@luillyfe
Last active October 17, 2018 15:26
Show Gist options
  • Save luillyfe/a541cc6d752464c49ed430a6ae65a3e6 to your computer and use it in GitHub Desktop.
Save luillyfe/a541cc6d752464c49ed430a6ae65a3e6 to your computer and use it in GitHub Desktop.
Angular: props are immutable?
// App Component
export class AppComponent {
title="News title";
content="A description should be here!";
}
// News component
@Component({
selector: 'news',
template: `
<div>
<h1>{{title}}</h1>
<div>{{content}}</div>
<button (click)="mutateProps()">Mutate!</button>
</div>
`,
})
export class NewsComponent {
@Input() title: string;
@Input() content: string;
mutateProps() {
this.title = "Title changed!";
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment