我使用带有ng2-material的angular 2来显示radio和checkbox组件,在每个组件中,我看到我必须导入所有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] <<<<<<
答案 0 :(得分:1)
根据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。
答案 1 :(得分:0)
@firasKoubaa我想你可以使用这样的东西
import {MdList, MdListItem, MdContent, MdButton} from 'ng2-material/all';
或者像这样的事情
import {MdButton} from "/ng2-material/components/button/button";