Angular2 + ng2-material 导入
Angular2 + ng2-material import
我使用 angular 2 和 ng2-material 来显示单选和复选框组件,在每个组件中我看到我必须导入所有 ng2-material 内容最后只使用一个组件
=> 结果,它对我的应用程序收费并使其变慢。
我想知道我是否可以只导入我需要的组件,尽管在 ng2-material 文档中他们正在导入所有组件???
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {MATERIAL_DIRECTIVES, MATERIAL_PROVIDERS} from "ng2-material/all"; <<<<<
import {ROUTER_DIRECTIVES} from 'angular2/router';
import { CORE_DIRECTIVES, FORM_DIRECTIVES } from 'angular2/common';
@Component({
selector: 'radiobox',
templateUrl: '/radiobox.html',
styleUrls: ['radiobox.css'],
directives: [MATERIAL_DIRECTIVES] <<<<<<
@firasKoubaa 我想你可以用这样的东西
import {MdList, MdListItem, MdContent, MdButton} from 'ng2-material/all';
或者像这样的东西
import {MdButton} from "/ng2-material/components/button/button";
根据all.ts
文件,您可以通过自己的模块导入每个组件。该文件只是执行 export * from
并创建一些常量。
这里有一些内容 file:
import {MdAnchor, MdButton} from "./components/button/button";
import {MdCheckbox} from "./components/checkbox/checkbox";
import {MdContent} from "./components/content/content";
import {MdDataTable, MdDataTableHeaderSelectableRow, MdDataTableSelectableRow} from './components/data_table/data_table';
import {MdDialog} from "./components/dialog/dialog";
import {MdDivider} from "./components/divider/divider";
import {MdIcon} from "./components/icon/icon";
import {MdInk} from "./components/ink/ink";
import {
MdPatternValidator,
MdMaxLengthValidator,
MdMinValueValidator,
MdMaxValueValidator,
MdNumberRequiredValidator,
INPUT_VALIDATORS
} from "./components/form/validators";
import {MdMessage, MdMessages} from "./components/form/messages";
import {MdInput, MdInputContainer} from "./components/input/input";
import {MdList, MdListItem} from "./components/list/list";
import {MdProgressLinear} from "./components/progress_linear/progress_linear";
import {MdProgressCircular} from "./components/progress_circular/progress_circular";
import {MdPeekaboo} from "./components/peekaboo/peekaboo";
import {MdRadioButton, MdRadioGroup} from "./components/radio/radio_button";
import {MdRadioDispatcher} from "./components/radio/radio_dispatcher";
import {MdSwitch} from "./components/switcher/switch";
import {MdSubheader} from "./components/subheader/subheader";
import {MdSidenav, MdSidenavContainer} from "./components/sidenav/sidenav";
import {SidenavService} from "./components/sidenav/sidenav_service";
import {MdToolbar} from "./components/toolbar/toolbar";
import {MdTabs, MdTab} from "./components/tabs/tabs";
import {Media} from "./core/util/media";
export * from './components/button/button';
例如,如果您只想使用单选按钮:
import {
MdRadioButton, MdRadioGroup
} from "ng2-material/components/radio/radio_button";
参见同一文件的常量:https://github.com/justindujardin/ng2-material/blob/master/ng2-material/all.ts#L85。
我使用 angular 2 和 ng2-material 来显示单选和复选框组件,在每个组件中我看到我必须导入所有 ng2-material 内容最后只使用一个组件
=> 结果,它对我的应用程序收费并使其变慢。
我想知道我是否可以只导入我需要的组件,尽管在 ng2-material 文档中他们正在导入所有组件???
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {MATERIAL_DIRECTIVES, MATERIAL_PROVIDERS} from "ng2-material/all"; <<<<<
import {ROUTER_DIRECTIVES} from 'angular2/router';
import { CORE_DIRECTIVES, FORM_DIRECTIVES } from 'angular2/common';
@Component({
selector: 'radiobox',
templateUrl: '/radiobox.html',
styleUrls: ['radiobox.css'],
directives: [MATERIAL_DIRECTIVES] <<<<<<
@firasKoubaa 我想你可以用这样的东西
import {MdList, MdListItem, MdContent, MdButton} from 'ng2-material/all';
或者像这样的东西
import {MdButton} from "/ng2-material/components/button/button";
根据all.ts
文件,您可以通过自己的模块导入每个组件。该文件只是执行 export * from
并创建一些常量。
这里有一些内容 file:
import {MdAnchor, MdButton} from "./components/button/button";
import {MdCheckbox} from "./components/checkbox/checkbox";
import {MdContent} from "./components/content/content";
import {MdDataTable, MdDataTableHeaderSelectableRow, MdDataTableSelectableRow} from './components/data_table/data_table';
import {MdDialog} from "./components/dialog/dialog";
import {MdDivider} from "./components/divider/divider";
import {MdIcon} from "./components/icon/icon";
import {MdInk} from "./components/ink/ink";
import {
MdPatternValidator,
MdMaxLengthValidator,
MdMinValueValidator,
MdMaxValueValidator,
MdNumberRequiredValidator,
INPUT_VALIDATORS
} from "./components/form/validators";
import {MdMessage, MdMessages} from "./components/form/messages";
import {MdInput, MdInputContainer} from "./components/input/input";
import {MdList, MdListItem} from "./components/list/list";
import {MdProgressLinear} from "./components/progress_linear/progress_linear";
import {MdProgressCircular} from "./components/progress_circular/progress_circular";
import {MdPeekaboo} from "./components/peekaboo/peekaboo";
import {MdRadioButton, MdRadioGroup} from "./components/radio/radio_button";
import {MdRadioDispatcher} from "./components/radio/radio_dispatcher";
import {MdSwitch} from "./components/switcher/switch";
import {MdSubheader} from "./components/subheader/subheader";
import {MdSidenav, MdSidenavContainer} from "./components/sidenav/sidenav";
import {SidenavService} from "./components/sidenav/sidenav_service";
import {MdToolbar} from "./components/toolbar/toolbar";
import {MdTabs, MdTab} from "./components/tabs/tabs";
import {Media} from "./core/util/media";
export * from './components/button/button';
例如,如果您只想使用单选按钮:
import {
MdRadioButton, MdRadioGroup
} from "ng2-material/components/radio/radio_button";
参见同一文件的常量:https://github.com/justindujardin/ng2-material/blob/master/ng2-material/all.ts#L85。