Menu
CoddyTech

回顾:共享状态

本课属于 Coddy Angular 学习旅程的“基础知识”单元。第 45 课,共 55 课。

challenge icon

挑战

中等

创建 PassStore,使其私有数量初始值为 1,并包含只读的 count 以及按每张 8 计算的 cost。Add 会增加数量,最多增加到 3。Reset 会将其恢复为 1。注入该 store 并显示 count 和 cost;达到上限后重复调用 Add 必须使 cost 保持为 24。

编辑所提供的文件。编辑后点击 运行预览 刷新预览,然后使用检查或运行代码对你的作品进行评分。请保留要求的元素 ID。

亲手试试

<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="styles.css"></head><body><app-root></app-root><script type="module" src="main.ts"></script></body></html>

基础知识中的所有课