I am creating a v2 for my UI. I want to keep the old UI and make changes. So I was thinking of keeping the name of new component same as old one.
So it is possible to have 2 different component with same name?
I am creating a v2 for my UI. I want to keep the old UI and make changes. So I was thinking of keeping the name of new component same as old one.
So it is possible to have 2 different component with same name?
What you could do is have two Classes one old and one new, with semantic naming rather than new and old of course, and within the master component class, have the logic for switching between the two.
or you could import as Alias, which means both classes can be the same name but where you use it obviously has to be different:
import { MyComponent as OldComponent } from '../old/my-component'
import { MyComponent} from '../new/my-component'
The best course of action to create a v2 would be to either use version control to branch from your old UI or to refactor your app to use your new UI instead. Under no circumstances I would recommend to create components with the same name especially when they serve the same purpose. It would only be confusing to yourself as well as other developers.
With that being said, if you need components to share a common logic. I would suggest you make your components inherit a base class:
export abstract class BaseComponent implements OnInit {
ngOnInit() {
// Example
}
}
@Component({
selector: 'a-selector'
})
export class NewComponent extends BaseComponent {
}