我对 angular 很陌生,我想使用鼠标悬停事件更改 src 值。我们如何在 angular 4 或更高版本中做到这一点?请帮我。
export const ROUTES: RouteInfo[] = [
{ path: '/dashboard', title: 'Dashboard', icon: 'fa fa-tachometer', class: '' ,name:'',src:"../../../../assets/images/header-icon.png",srcOn:"../../../../assets/images/dashboard_highlighted.png"},
{ path: '/forms', title: 'Forms', icon:'fa fa-eyedropper', class: '',name:'',src:"../../../../assets/images/dashboard_highlighted.png",srcOn:""},
{ path: '/tables', title: 'Desk Blotter', icon:'fa fa-pencil', class: '' ,name:'',src:"../../../../assets/images/dashboard_highlighted.png",srcOn:""},
{ path: '/bs-element', title: 'Admin', icon:'fa fa-picture-o', class: '' ,name:'',src:"../../../../assets/images/dashboard_highlighted.png",srcOn:""},
{ path: '/login', title: 'Logout', icon:'fa fa-power-off', class: '',name:'',src:"../../../../assets/images/dashboard_highlighted.png",srcOn:"" },
];
<li *ngFor="let menuItem of menuItems" routerLinkActive="active" class="{{menuItem.class}}" >
<a [routerLink]="[menuItem.path]" name="{{menuItem.name}}">
<img src="{{menuItem.src}}" style="width:66%;" …Run Code Online (Sandbox Code Playgroud) 我有一个父组件,它基本上是由两个子组件组成的表单,每个子组件由一堆inputs. 这是父组件模板:
<!-- Bunch of user selected filters -->
<app-filters #filters>
</app-filters>
<!-- Bunch of user selected grouping options -->
<app-grouping-options #groupingOptions>
</app-grouping-options>
<!-- Emit an event with the composed query so
other component can recover and show the data
to the user -->
<button (click)="emitQuery(filters.getFilteringCriteria(), groupingOptions.getGroupingCriteria())">Search</button>
Run Code Online (Sandbox Code Playgroud)
我感兴趣的部分是filters.getFilteringCriteria()和groupingOptions.getGroupingOptionsCriteria()方法调用。我不确定这是否是一个好的做法,特别是因为它似乎打破了预期的数据流:从父级到子级通过属性绑定,从子级到父级通过 events。但是我真的不知道在这种情况下如何进行,因为搜索的功能确实是一个方法,而不是一个属性。
除此之外,引用子组件的最佳方法是什么?通过模板变量或使用@ViewChild?
谢谢你的帮助。
我在 Angular6 中开发了一个项目。需要为实时聊天开发部分。为此,我在我的 asp.net 核心 Web Apiproject 中使用 SignalR。现在我想在我的 Angular 项目中使用这个 Web Api 参考。
我正在使用此链接。
但是在 App.Component.ts 中提供 Web Api url 时,我收到以下错误:
“HubConnection”类的构造函数是私有的,只能在类声明中访问。
应用组件.ts:
import { HubConnection } from '@aspnet/signalr';
import { Message } from 'primeng/api';
export class AppComponent implements OnInit {
public _hubConnection: HubConnection;
msgs: Message[] = [];
constructor() {
}
ngOnInit() {
this._hubConnection = new HubConnection('http://localhost:1874/notify'); // getting error on this line.
Run Code Online (Sandbox Code Playgroud)
编辑:尝试以下代码:-
修改后的 App.Component.ts :
import { HubConnection } from '@aspnet/signalr';
import * as …Run Code Online (Sandbox Code Playgroud) 当我尝试在我的 Angular 6 应用程序中的 formGroup 上使用 disable 方法时,我在浏览器控制台中收到此错误:
类型错误:this.personForm.disable 不是函数
尽管文档中提到了该方法,并且VS Code 甚至在此快照中建议了该方法。
我的代码在这里:
// ... many parts skipped, the form here is template driven
// but still personForm is a FormGroup ,
// I am trying to disable the whole FormGroup with all child elements
@ViewChild('personForm') personForm: FormGroup;
if (true) {
// if I console.log here the form, I can see it is created already
console.log(this.personForm);
// output of console.log is
// NgForm {submitted: false, …Run Code Online (Sandbox Code Playgroud) 是否可以声明一个数组并使用它来引导 module.ts 中的多个组件。我正在尝试这样的事情
export var initialComponents = [];
initialComponents.push(AppComponent);
if(condition) {
initialComponents.push(IchFooterComponent);
}
Run Code Online (Sandbox Code Playgroud)
进而
bootstrap: initialComponents
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误
错误:模块 oa 被引导,但它没有声明“@NgModule.bootstrap”组件,也没有声明“ngDoBootstrap”方法。请定义其中之一。
我对 Angular 很陌生。我正在使用 Angular 6 和 NGXS 进行状态管理。
我的 NGXS 商店有一个userreducer,其接口是
/* src/app/store/models/user.model.ts */
export interface User {
serverToken? : string;
// and other unrelated stuff
}
Run Code Online (Sandbox Code Playgroud)
我想用serverToken在Authorization标题中HttpInterceptor。
这是我目前的HttpInterceptor代码
import {Store, Select} from '@ngxs/store';
import {Injectable} from '@angular/core';
import {HttpInterceptor, HttpHandler, HttpRequest, HttpEvent} from '@angular/common/http';
import {Observable} from 'rxjs';
import {User} from '../store/models/user.model';
@Injectable()
export class ApiInterceptor implements HttpInterceptor {
constructor(private store : Store) {}
@Select()user$ : Observable < User …Run Code Online (Sandbox Code Playgroud) 我创建了一个名为 login 的新组件,我必须为该组件(login.component.html)设置背景图像,仅适用于该组件。我尝试了堆栈溢出中提供的许多解决方案。但是图像没有设置为全高身体。下面是我的项目文件。
索引.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序组件.html
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
@Component({
AppComponent,
LoginComponent
})
imports: [
BrowserModule,
RouterModule.forRoot([
{ path: '', pathMatch: 'full', redirectTo: 'login' },
{ path: 'login', component: LoginComponent },
])
],
providers: [],
bootstrap: …Run Code Online (Sandbox Code Playgroud) 如何将 PouchDB 添加到 Angular 5 或 6 项目?我正在使用 Angular 6,但找不到任何方法来做到这一点。
如果我有 Component 类
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
}
Run Code Online (Sandbox Code Playgroud)
和 index.html 是
<div>
<my-app></my-app>
</div>
Run Code Online (Sandbox Code Playgroud)
组件的宿主元素是什么?会是<div>还是<my-app>?如果是<my-app>,有没有办法从 访问<div>(的父AppComponent)AppComponent?
我有一个应用程序,我在其中保留了那个 dist 文件夹,我们在我的服务器上成功构建了完整的生产版本后获得了该文件夹。一切正常,所有模块和组件都运行良好。在我手动重新加载浏览器窗口之前,它会引发以下错误。我还使用 base-href -- /dist/ 构建了项目
Object not found!
The requested URL was not found on this server. If you entered the URL
manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×6
typescript ×3
angular5 ×1
css ×1
frontend ×1
javascript ×1
ngxs ×1
pouchdb ×1
rxjs ×1
signalr ×1
signalr-hub ×1