angular-mock-to-real-api
Rewrite an Angular app's mocked/in-memory services to call a real backend API (HttpClient). Covers the predictable breakage chain — DTO/property renames that ripple into templates, duplicate interceptor/service files that shadow the real implementation, and phantom TS errors from stale incremental build caches. Use when the user says "connect the frontend to the real API", "kill the mocks", or "wire services to the backend".
- License 许可
- MIT
- 最近更新
- 2026-10-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- angular-mock-to-real-api
- license
- MIT
- metadata
- { "author": "ks-knowledge-sharing project learnings", "version": "1.0" }
- description
- Rewrite an Angular app's mocked/in-memory services to call a real backend API (HttpClient). Covers the predictable breakage chain — DTO/property renames that ripple into templates, duplicate interceptor/service files that shadow the real implementation, and phantom TS errors from stale incremental build caches. Use when the user says "connect the frontend to the real API", "kill the mocks", or "wire services to the backend".
03 SKILL.md 正文
Angular: Mock -> Real API
Recurring task for this user (Angular 20 frontend over a NestJS API). The refactor is mechanical but the build breakage is a fixed set of traps — fix them all in one pass.
Sequence
- Add an API config constant (e.g.
src/app/core/config/api.config.tsexportingAPI_CONFIG.baseUrl = 'http://localhost:3000/api'). Keep it out of components so you can swap to a deployed URL in one place. - Inject
HttpClientinto each service and replace mockof([...])/ hardcoded arrays with realhttp.get/post/patch. ConfirmprovideHttpClient()is inapp.config.ts(it usually is). - Align DTOs to the real response shape. Inspect the live endpoint first:
curl -s 'http://localhost:3000/api/articles?limit=1'— note exact field names and types. The backend field names are authoritative; change the Angular interface to match, not the other way around. - Map response -> component model in the service (so components don't change), OR update components. Prefer mapping in the service to limit blast radius.
Trap 1 — property rename ripples into templates
If the backend renames a field (e.g. categoryId -> category, or changes type from number to UUID string), every .categoryId property access breaks — including in .html templates and formValue.categoryId passed to create calls.
- Grep the whole
srcfor the old name:grep -rn "categoryId" src --include=*.ts --include=*.html. - Fix property reads (
article.categoryId->article.category). Leave reactive-formformControlName="categoryId"andform.get('categoryId')alone — those are control keys, not the article property. - Templates:
<img [src]="getPlaceholderImage(article()!.categoryId)">->article()!.category.
Trap 2 — duplicate interceptor/service shadows the real one
A project can have BOTH auth.interceptor.ts (Angular default, 444B, references a refreshToken() that no longer exists) AND auth-interceptor.ts (hyphen, the one app.config.ts actually imports). The unused one still gets compiled by tsc (src/**/*.ts) and throws a phantom error.
- Find duplicates:
find src -name "auth*.ts". - Delete the dead duplicate (
rmthe hyphen file + its.spec.ts) ifapp.config.tsimports the other. The live error "Property 'refreshToken' does not exist" on a line number beyond the real file's length is the tell.
Trap 3 — phantom TS errors from stale incremental cache
After fixing everything, tsc --noEmit / ng build may STILL report errors that reference lines you already edited (e.g. "categoryId does not exist" on a line now reading category). This is stale .tsbuildinfo / .angular cache.
- Nuclear clear:
find . -name "*.tsbuildinfo" -not -path "*/node_modules/*" -delete; rm -rf .angular node_modules/.cache; rm -rf dist. - Then rebuild. If
ng build --no-aotstill fails, runnpx tsc --noEmit -p tsconfig.app.jsonto get the true error list (bypasses the bundler). - A real syntax error (e.g. a dangling
)left by a half-applied patch) will show asTS1128/TS1005at a specific line — read that file region, don't trust the earlier phantom lines.
Verification
npx tsc --noEmit -p tsconfig.app.jsonmust be clean (empty output).npx ng build --configuration developmentmust exit 0. Template warnings (e.g.controlFlowPreventingContentProjection) are non-blocking; onlyerrorlines block.- Optional runtime check: serve the app (
ng serve) and confirm a component fetches from the live API (Network tab / curl the served index). At minimum, confirm the service code references the realAPI_CONFIG.baseUrl+ correct paths and the backend returns the expected shape.
Commit each slice
Per the maker/checker loop: after a verified build, commit the frontend wiring as its own commit before moving to the next screen/feature. Don't batch unrelated slices.
04 同仓库更多 Skills
blocked-page-recovery
Use when a fetch fails: 403/429, paywall, WAF, bot wall.
gemini-vision-fallback
Vision fallback: Gemini REST API if vision_analyze blocked.
twitter-cli
Use twitter-cli for ALL Twitter/X operations — reading tweets, posting, replying, quoting, liking, retweeting, following, searching, user lookups. Invoke whenever user requests any Twitter interaction.
prism-scan
Structural analysis through dynamically generated cognitive lenses. Generates the optimal analytical lens for the specific code/artifact, then executes it. Finds conservation laws, structural invariants, and concrete bugs that vanilla analysis misses. Use on any code file, system design, or text artifact.
prism-reflect
Constraint transparency: analyzes an artifact structurally, then analyzes what its own analysis concealed. Produces a conservation law AND a constraint report showing what was maximized, what was sacrificed, and what to investigate next. The only AI skill that knows what it can't see.
prism-full
Full Prism: multi-pass structural analysis with mandatory adversarial self-correction. Designs custom analytical passes, executes them with chaining, then attacks its own findings before synthesizing. Use for maximum depth on important code or artifacts.