2016-11-11 61 views
1

通過angular2 RC.1,我們創建了一個自定義管道並導入了一些我們需要創建管道的類。 只有現在我們遷移到最終的角度釋放,我們無法導入任何我們需要的類。Angular2創建導入問題的自定義管道

import { isBlank, isString, isArray, StringWrapper, CONST } from 'angular2/src/facade/lang'; 
import { BaseException } from 'angular2/src/facade/exceptions'; 
import { ListWrapper } from 'angular2/src/facade/collection'; 
import { InvalidPipeArgumentException } from 'angular2/src/common/pipes/invalid_pipe_argument_exception'; 

有人可以告訴我們在哪裏可以找到這個類,我們無法找到它們,也沒有在代碼中找到它們。那麼他們所發生的一切呢?

回答

1

如果我沒有記錯的話,這些都是在RC6的時間範圍內有意識地從公共API中重新構造出來的。如果你通過github上的源代碼,你會發現在大多數情況下,這些代碼存在但不再導出到任何地方。有一個github上的問題可以追溯到的2015年4月,其背後凸顯從公開曝光除去這些內部公用事業思路:

Facades are here to abstract JS/Dart differences. We don't want to be in business of providing general helper functions as there are already plenty of libraries that do just that in a generic manner. Facades are minimal and for internal use - we don't want to grow those to sth generic as not to add too many bytes to the framework.

https://github.com/angular/angular/issues/3886

你要麼需要找到實現你所需要的庫或建立你自己的。

isString,例如是一個簡單的typeofCheck if a variable is a string

可以的isBlank通過檢查,如果它是一個字符串,然後看如果事情是空白與正則表達式來完成。

異常將從錯誤中派生:How do I extend a host object (e.g. Error) in TypeScript您拋出新錯誤的位置。

你問他們發生了什麼,我回答了。

+0

好吧,但是如果你要創建我們自己的管道,那麼他們怎麼能不能實現一個BaseException或一個InvalidPipeArgumentException,這個管道就是在支持什麼。 –

+0

而不是'ListWrapper.forEachWithIndex'我可以使用簡單的 'Array.forEach((record,index)=> {});'這沒關係 但是應該有一個庫給我一個'isString'函數?你認識一個人嗎? 如何在管道上拋出異常?在出現'BaseException'和'InvalidPipeArgumentException'之前,應該有類似或不類似的東西? –