Giter VIP home page Giter VIP logo

angular-demo4's Introduction

todoMVC 練習

初始化

  • 切分元件,將 app 元件中的內容,分散至 header, listfooter 元件中。
  • 新增服務元件 list-service,並利用環境變數檔,找到正確的 api 路徑,撰寫 非同步請求 邏輯。

header 元件

  • <input/> 按下 enter 後,發出 http request,新增 todo 事項。
    • 成功,清空 input,更新 list 元件。
    • 失敗,input 保留,發出 alert 訊息 - 新增失敗

list 元件

  • 利用服務 list-service 拿到代辦資料 task
  • 利用列表資料渲染畫面。
    • task 的名稱綁定至 <li/> 元素中的 <label/> 元素中。
    • 利用 task 的屬性 isDone,決定事項是否已完成,完成事項的 <li/> 元素 class 名稱,應含有 completed
  • <li/> 元素中的 <label/> 元素,新增 雙擊開啟編輯 功能
    • 編輯 模式啟動後,<li/> 元素 class 名稱,應含有 editing
    • 編輯 模式啟動後, class 名稱為 edit<input/> 才可出現在 HTML 結構中
    • 當使用者不再 focus 上述 <input/> 或在該 <input/> 按下 enter 時,解除編輯模式,並發出 http request 更新 該事項
    • 呈上,若使用者按下 ESC 鍵,不更新事項,解除編輯模式
  • classdestroy<input/> 上,完成刪除功能,發出 http request 刪除 該事項
  • classtoggle<input/> 上,完成更新 已完成狀態 功能
  • classtoggleAll<input/> 上,完成更新全部事項 已完成狀態 功能

footer 元件

  • 當事項數量為 0 時,不顯示
  • 顯示當前事項數量
    • <strong/> 元素內,顯示已完成的事項數量
    • <strong/> 元素後,字樣 left 之前,顯示 未完成 的事項數量
  • classclear-completed 的按鈕上,完成 清除所有 已完成事項功能

Reference


開發中注意事項

  • 透過 code snippet 引入 EventEmitter 事件物件時,要注意不要用錯 import 來源
    • from protractor 裡面也有 EventEmitter
    • 我們實際要使用的 import 來源是 @angular/core 來源內的 EventEmitter
  • 在使用 ng g s list 時,如果不想同時建立目錄
    • 可加上 --flat 參數,如此就只會建立 list.service.ts 檔案

目前遇到的問題紀錄

  • core\list-service.ts 當中還不知道如何實現外部傳入需要執行的事件流程
  • 如果短時間內進行更新 Taskclear complete 會造成 json-server 異常問題

angular-demo4's People

Contributors

weweaaa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.