I have the following examples:
without public;
export class Persona {
name: string;
lastName: string;
dni: string;
}
With public;
export class Persona {
public name: string;
public lastName: string;
public dni: string;
}
If I leave the attribute without the access modifier, is it public by default? It may be something basic but I don't know what the correct definition would be (I want the attributes to be public to access them from the html in angular 5).
In Typescript there are 3 access modifiers: public, private and protected ( See Reference for more details)
public
: It is the default modifier . This is so because Javascript does not have these modifiers and everything is public, so for consistency it is normal for it to be the default value.private
: The elements (attributes and methods) are only visible inside the class.protected
: Elements are only visible within the class and in classes that directly inherit from it.According to the documentation , in the Public, private, and protected modifiers subheading :
So there is no difference between the two.