中的選項之間要求一個屬性我正在創建一個角度指令,我希望用戶指定指令的「類型」。在指令
例如:
<my-directive type-a></my-directive>
或
<my-directive type-b></my-directive>
或
<my-directive type-c></my-directive>
我知道我可以做:
<my-directive type="a"></my-directive>
然後需要type屬性,但然後我在做字符串匹配。無論如何,通過要求「type-a」,「type-b」或「type-c」中的任何一個出現,可以這樣做嗎?
字符串比較而不是什麼?屬性比較你需要確保類型是在編譯指令時設置的,否則你會拋出一個錯誤。這有什麼難的? – Mike