Advanced Angular — Series 3

Preview — 3 of 10 questions

The current users data is now stale on the server, but `userId` hasnt changed. How do you force a refetch without changing the request?

javascript
const userId = signal(1);
const user = resource({
  request: () => ({ id: userId() }),
  loader: ({ request }) => fetchUser(request.id),
});
ARead user.value() again — resources refetch on every read
BCall userId.set(userId()) with the same value to trick reactivity
CDestroy and recreate the whole resource() call
DCall user.reload() — it's the resource's built-in method to re-run the loader for the current request value, independent of whether the request itself changed

An outgoing request passes through these three interceptors. Which one sees the raw request first?

javascript
provideHttpClient(
  withInterceptors([loggingInterceptor, authInterceptor, cacheInterceptor])
);
AloggingInterceptor — interceptors run in the order listed in the array for the outgoing request, each one calling next(req) to pass control to the next
BcacheInterceptor, because caching should always run first
CauthInterceptor, since Angular always prioritizes auth-related interceptors
DAll three run simultaneously on the same request object

Why is calling inject() directly inside this arrow function legal?

javascript
export const authGuard: CanActivateFn = () => {
  const auth = inject(AuthService);
  const router = inject(Router);
  return auth.isLoggedIn() ? true : router.createUrlTree(['/login']);
};
AIt isn't legal outside a class — this would throw at runtime
BCanActivateFn implementations require a @Injectable() decorator that isn't shown
CThe router invokes guard functions from within an active injection context during navigation, so inject() works the same way it would inside a constructor — no class or decorator is needed
Dinject() works anywhere in the codebase unconditionally, guard or not

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.