I'm making a few custom components that will be used in different parts of my project (possibly more than one project) and I wanted to have a few properties to render in the HTML template of those components, but also not be available as public for other components that might include the said component.
For example:
My generic component
@Component({
selector: 'my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.scss'],
})
export class MyComponent implements OnInit {
title:string='TITLE'; // public because otherwise the template can't use it
}
Other component that includes MyComponent in its template
@Component({
selector: 'other-component',
templateUrl: './other-component.component.html',
styleUrls: ['./other-component.component.scss'],
})
export class OtherComponent implements OnInit {
@ViewChild(MyComponent) my:MyComponent;
...
fun(){
this.my.title = "other title"; // this is what I don't want to happen
}
...
}
Is there a way to avoid OtherComponent to be able to use MyComponent.title?