All posts

7 min read

Vue developer learning Angular: what carries over, what's new, 30-day plan

Practical guide for Vue developers transitioning to Angular, covering transferable concepts, new patterns, common pitfalls, a 30‑day learning plan, and…

What carries over

Vue conceptAngular equivalentHow it helps you transition
Component‑based UI@Component classes with templatesBoth frameworks treat UI as reusable, isolated units. Your mental model of props, slots, and lifecycle stays valid; you just declare them differently.
Reactive data flowRxJS Observable streams and async pipeVue’s reactivity system is replaced by Angular’s change detection, but the idea of “data drives the view” is identical. When you bind to an Observable with `
Single‑File Component (SFC) styleSeparate .ts, .html, .scss files (or inline templates)The separation of template, style, and logic is still enforced. Think of the <script> part of an SFC as the component class, the <template> as the HTML file, and <style> as the SCSS file.
Scoped CSSView‑Encapsulation (encapsulation: ViewEncapsulation.Emulated)Angular’s default emulated encapsulation gives you the same “scoped” behavior you rely on in Vue’s <style scoped>.
Vue RouterAngular Router (RouterModule)Both provide declarative route definitions, lazy‑loading, and navigation guards. Your experience with route params, query strings, and navigation hooks maps directly to ActivatedRoute, Router.navigate, and CanActivate.
Vuex storeNgRx (or built‑in @Injectable services)Central state management is still a pattern. If you use Vuex modules, think of NgRx feature slices; if you use simple Vuex, a singleton service with BehaviorSubjects works the same way.
Template syntaxAngular template syntax (*ngIf, *ngFor, [property], (event))The declarative binding style is familiar; you just swap v‑ directives for * structural directives and bracket/parenthesis syntax.
CLI scaffoldingAngular CLI (ng generate component …)Both CLIs generate boilerplate, enforce conventions, and set up testing files. Your habit of running npm run serve becomes ng serve.

The biggest mental shift is moving from Vue’s “option API” (or composition API) to Angular’s class‑based components with decorators. But the underlying principles—component hierarchy, unidirectional data flow, and declarative templates—remain the same, so you can reuse much of your existing intuition.


What's new

Below is a tiny “counter” component that increments a number when a button is clicked.

Vue (Composition API)

<template>
  <div>
    <p>Count: {{ count }}</p>
    <button @click="increment">Add</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const count = ref(0)
function increment() {
  count.value++
}
</script>

<style scoped>
button { margin-top: 0.5rem; }
</style>

Angular

// counter.component.ts
import { Component } from '@angular/core'

@Component({
  selector: 'app-counter',
  templateUrl: './counter.component.html',
  styleUrls: ['./counter.component.scss']
})
export class CounterComponent {
  count = 0

  increment(): void {
    this.count++
  }
}
<!-- counter.component.html -->
<div>
  <p>Count: {{ count }}</p>
  <button (click)="increment()">Add</button>
</div>
/* counter.component.scss */
button { margin-top: 0.5rem; }

What changed and why

  1. File structure – Angular prefers separate files for class, template, and styles. This encourages clear separation of concerns and enables tooling like AOT compilation.
  2. Class‑based component – Instead of a setup function, you write a TypeScript class. All component state lives as class properties, and methods become class methods.
  3. Decorator metadata – @Component supplies the template URL, style URLs, and selector. Decorators are a core part of Angular’s compile‑time metadata system.
  4. Event binding syntax – Vue’s @click becomes Angular’s (click). Angular distinguishes between property binding ([prop]) and event binding ((event)).
  5. No explicit ref – Angular’s change detection tracks plain properties; you don’t need a wrapper like Vue’s ref. If you need asynchronous streams, you’d use RxJS Observables instead.

Other notable new concepts:

  • Dependency Injection (DI) – Services are injected via the constructor. This replaces Vue’s provide/inject pattern and makes testing easier.
  • Modules (NgModule) – Angular groups components, directives, and pipes into modules, which define the compilation context. Vue’s plugin system is lighter; you’ll now think in terms of feature modules.
  • Ahead‑of‑Time (AOT) compilation – Templates are compiled to highly optimized JavaScript before runtime, improving load performance.
  • Typed forms – Angular’s FormBuilder and reactive forms give you a strongly typed way to manage form state, unlike Vue’s template‑driven forms.

Common pitfalls

PitfallWhy it happensHow to avoid it
Mutating inputs directlyVue allows mutating a prop in a child (with a warning). Angular treats @Input() as immutable; changing it won’t trigger change detection.Always treat @Input() as read‑only. Emit changes via @Output() events or use a shared service.
Forgetting to unsubscribeVue’s reactivity cleans up automatically. Angular subscriptions to Observables stay alive unless you unsubscribe.Use the async pipe in templates, or implement OnDestroy and call subscription.unsubscribe().
Using any everywhereVue’s flexibility can lead to lax typing. Angular’s ecosystem expects strong TypeScript typing.Enable strict mode in tsconfig.json and type all services, component inputs, and forms.
Assuming two‑way binding works the sameVue’s v-model on custom components is straightforward. Angular’s [(ngModel)] works only with FormsModule and requires ControlValueAccessor for custom components.Prefer reactive forms (FormControl) for complex components; implement ControlValueAccessor only when you need template‑driven two‑way binding.
Neglecting module importsVue components are globally available once registered. Angular requires the component’s module to be imported wherever it’s used.Keep a “shared” module for reusable components and import it into feature modules.
Relying on this in callbacksVue automatically binds methods to the component instance. In Angular, arrow functions preserve this, but regular functions lose the context.Use arrow functions for callbacks or bind explicitly (this.method.bind(this)).
Overusing ngIf/ngFor with heavy logicVue’s template expressions are cheap; Angular evaluates them on every change detection cycle, which can be costly.Move heavy calculations to component getters with memoization or use trackBy with *ngFor.

Your 30‑day plan

Week 1 – Foundations

  1. Install the Angular CLI and generate a new workspace: npm i -g @angular/cli && ng new vue‑to‑angular --routing --style=scss.
  2. Explore the project layout – locate app.module.ts, app.component.*, and the src/environments folder.
  3. Build a simple component using ng generate component hello. Add a property and bind it in the template.
  4. Read the Angular style guide (focus on naming, file organization, and DI).

Mini‑project: Create a “Hello World” page that displays a greeting based on a route parameter (/hello/:name). Use ActivatedRoute to read the param and display it.

Week 2 – Data flow & services

  1. Implement a shared service (ng generate service counter) that holds a BehaviorSubject<number> and exposes increment() and value$.
  2. Consume the service in two components (e.g., CounterDisplayComponent and CounterButtonComponent). Use the async pipe for the observable.
  3. Add routing: a lazy‑loaded feature module (ng generate module feature --route feature --module app.module).
  4. Experiment with Angular forms – create a reactive form that adds items to a list.

Mini‑project: Build a “Todo” app with a service‑backed list, a form to add items, and a component to toggle completion. Persist the list in localStorage via the service.

Week 3 – Advanced patterns

  1. Learn NgRx basics (store, actions, reducers, selectors). Scaffold a feature slice with ng generate store.
  2. Migrate the Todo state from the service to NgRx. Observe how actions replace direct method calls.
  3. Create a custom pipe (ng generate pipe truncate) and use it in a template.
  4. Implement a ControlValueAccessor for a reusable date‑picker component.

Mini‑project: Extend the Todo app to include filtering (All / Active / Completed) using NgRx selectors and a custom pipe for display.

Week 4 – Performance, testing, and deployment

  1. Enable AOT and production builds: ng build --configuration production. Inspect the generated bundles.
  2. Write unit tests with Jasmine/Karma for a component and a service (ng test). Add a simple end‑to‑end test with Cypress (ng e2e).
  3. Profile change detection using ng.profiler or the Angular DevTools extension. Add OnPush change detection strategy where appropriate.
  4. Deploy to a static host (ng deploy with a suitable adapter, or copy dist/ to a server).

Capstone project: Refactor the Todo app into a feature module with NgRx, lazy loading, OnPush components, and a CI pipeline that runs lint, test, and build steps. Deploy it to a free static hosting service.


FAQ

How do I migrate a Vuex store to NgRx?

Treat Vuex modules as NgRx feature slices: actions become createAction, mutations become reducers, and getters become selectors. Use StoreModule.forFeature to register the slice.

Do I need to learn RxJS immediately?

You can start with simple services and BehaviorSubjects, but most Angular APIs (HTTP, router events, forms) return Observables, so basic RxJS operators (map, switchMap, tap) become essential early on.

Can I still use single‑file components?

Angular does not support Vue‑style SFCs out of the box. However, you can embed inline templates and styles in the @Component decorator if you prefer a single file for tiny components.

Is Angular slower than Vue because of its change detection?

Angular’s default change detection runs on every async event, but it’s highly optimized and can be made deterministic with OnPush strategy. In most real‑world apps the performance difference is negligible when best practices are followed.

Keep going

#vue #angular #migration #learning