我正在尝试在Angular-CLI项目中使用Angular 2的材料实现工具提示。文档有点不清楚究竟需要什么。我需要的只是一个标准的工具提示弹出窗口。
在我的组件HTML中,我有这个:
<button md-raised-button mdTooltip="This is a tooltip!" mdTooltipPosition="below">Button</button>
在我的app.module中我有这个(为简洁而编辑):
import { MaterialModule } from '@angular/material';
@NgModule({
imports: [
MaterialModule.forRoot(),
]
我的package.json中也列出了材质和hammer.js(因为hammer.js显然是mdTooltip的依赖项)。这是我的package.json:
{
"name": "abc",
"version": "0.0.1",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.2.3",
"@angular/compiler": "2.2.3",
"@angular/core": "2.2.3",
"@angular/forms": "2.2.3",
"@angular/http": "2.2.3",
"@angular/material": "^2.0.0-beta.1",
"@angular/platform-browser": "2.2.3",
"@angular/platform-browser-dynamic": "2.2.3",
"@angular/router": "3.2.3",
"@types/socket.io": "^1.4.27",
"@types/socket.io-client": "^1.4.29",
"angular-in-memory-web-api": "~0.1.15",
"angular2-chartjs": "^0.1.6",
"chart.js": "^2.4.0",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"ng2-charts": "^1.4.1",
"rxjs": "5.0.0-beta.12",
"socket.io": "^1.7.2",
"socket.io-client": "^1.7.2",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
"devDependencies": {
"@angular/compiler-cli": "2.2.3",
"@types/hammerjs": "^2.0.34",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.22-1",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"typescript": "~2.0.3",
"typings": "^1.3.2",
"webdriver-manager": "10.2.5"
}
}
我不清楚我还需要导入到component.ts文件中还需要什么,如果需要的话,还需要这个工作。这是我现在对组件文件的所有内容:
import { MaterialModule } from '@angular/material';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-room',
templateUrl: './room.component.html',
styleUrls: ['./room.component.less']
})
export class RoomComponent implements OnInit {
otherImg = 'app/img/avatar.svg';
others = [
{ id: 1, name: 'John Smith' },
{ id: 2, name: 'Javier Sanchez' }
];
chat(other) {
console.log('Room chat function initiated...');
}
constructor() { }
ngOnInit() {
}
}
现在我在组件视图中看到一个按钮。但是,当我将鼠标悬停在按钮上或单击按钮时,不会显示工具提示。它显示了其他材料设计元素(凸起按钮样式等),但没有工具提示。
我的polyfills.ts文件如下所示:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
答案 0 :(得分:2)
使用md-tooltip
代替mdTooltip
:
<button md-raised-button md-tooltip="This is a tooltip!" mdTooltipPosition="below">Button</button>