我想实现应该动态生成的UI矩阵模式。通过接收输入参数,它应该确定什么是UI矩阵模式尺寸:例如9X3元素: 模式9x3元素
我使用Angular2.js,打字稿,SCSS。
html tamplate和.ts看起来:
import {Component, Input, OnInit} from 'angular2/core';
import {NgFor} from 'angular2/common';
@Component({
selector : 'game-pattern',
moduleId : module.id,
templateUrl: 'game-pattern.component.html',
styleUrls : ['game-pattern.component.css'],
directives : [NgFor],
})
export class GamePatternComponent implements OnInit {
@Input('CardType') public cardType: number;
public horizontalElementLocation: number;
public verticalElementLocation: number;
public rows: number[] = [];
public elements: number[] = [];
public y: number;
public x: number;
// public cardType = 3;
constructor() {
this.cardType = 3;
}
public ngOnInit() {
console.log('cardType ' + …Run Code Online (Sandbox Code Playgroud) 我正在创建一个组件然后它被设置为root组件然后我得到错误Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'.我已经使用RouterLink作为组件anotation中的指令但它无法工作.
app.routes.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { dogRoutes } from './Dogs/dog.routes';
import { catRoutes } from './Cats/cat.routes';
import {userRoutes} from "./Users/user.routes";
// Route Configuration
export const routes: Routes = [
{
path: '',
redirectTo: '/dogs',
pathMatch: 'full'
},
...catRoutes,
...dogRoutes,
...userRoutes
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import { Component } from …Run Code Online (Sandbox Code Playgroud) angular2-directives angular2-template angular2-routing angular
我有一个自定义开关,需要使用和不使用forms.即
定制switch.component.html
<div class="custom-switch" [formGroup]="parentGroup">
<input id="{{ id }}" name="status" type="checkbox"
[checked]="checked"
formControlName="{{ switchName }}"
(change)="onChange($event, id)" />
<label for="{{ id }}" class="label-default" data-toggle="tooltip" data-selector="true"
data-title="Switch"></label>
</div>
Run Code Online (Sandbox Code Playgroud)
定制switch.component.ts
import { Component, Input } from "@angular/core";
@Component({
selector : 'custom-switch',
template : 'custom-switch.component.html'
})
export class CustomSwitchComponent {
@Input('id') id : any = 'switch';
@Input('parentGroup') parentGroup : any;
@Input('switchName') switchName : any;
onChange() {
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
从父组件我调用表单子组件的组件为:
<custom-switch [parentGroup]="form" [switchName]="'switch'"></custom-switch>
Run Code Online (Sandbox Code Playgroud)
我想用:
<custom-switch></custom-switch>
Run Code Online (Sandbox Code Playgroud)
并删除
[formGroup]="parentGroup" 和
formControlName="{{ switchName …
我在app模板(根组件的模板)中定义了一个spinner/loader元素
<!--I have it here so that I don't have to paste it in all my templates-->
<div #spinner></div>
Run Code Online (Sandbox Code Playgroud)
在我的子组件中,我试图使用它来访问它,@ViewChild但似乎总是返回undefined.我在子组件中访问它的代码是
@ViewChild('spinner', { read: ViewContainerRef }) container: ViewContainerRef; //this is always undefined
Run Code Online (Sandbox Code Playgroud)
但是,当我将我#spinner的子组件的HTML 放入其中时,它会被正确地拾取.
有没有办法将子组件中父组件中定义的元素作为一个ContainerRef?
我需要视图引用来动态地使用它创建组件ComponentFactoryResolver.
这似乎是一个类似的问题,但无法找到克服的方法.
编辑:我现在使用与observable的共享服务,但它仍然没有引发事件.next.
这是我的代码 SpinnerComponent
@Component({
selector: 'spinner',
styleUrls: ['app/styles/spinner.component.css'],
template:
`<div [hidden]="state.visible" class="in modal-backdrop spinner-overlay"></div>
<div class="spinner-message-container" aria-live="assertive" aria-atomic="true">
<div class="spinner-message" [ngClass]="spinnerMessageClass">{{ state.message }}</div>
</div>`
})
export class SpinnerComponent {
constructor(spinnerService: SpinnerService) { …Run Code Online (Sandbox Code Playgroud) 我通过选择预先存在的组件创建了动态组件实例.例如,
@Component({
selector: 'dynamic-component',
template: `<div #container><ng-content></ng-content></div>`
})
export class DynamicComponent {
@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;
public addComponent(ngItem: Type<WidgetComponent>,selectedPlugin:Plugin): WidgetComponent {
let factory = this.compFactoryResolver.resolveComponentFactory(ngItem);
const ref = this.container.createComponent(factory);
const newItem: WidgetComponent = ref.instance;
newItem.pluginId = Math.random() + '';
newItem.plugin = selectedPlugin;
this._elements.push(newItem);
return newItem;
}
}
Run Code Online (Sandbox Code Playgroud)
我之前存在的组件是ChartWidget和PatientWidget,它扩展了我想在容器中添加的类WidgetComponent.例如,
@Component({
selector: 'chart-widget',
templateUrl: 'chart-widget.component.html',
providers: [{provide: WidgetComponent, useExisting: forwardRef(() => ChartWidget) }]
})
export class ChartWidget extends WidgetComponent implements OnInit {
constructor(ngEl: ElementRef, renderer: Renderer) {
super(ngEl, renderer);
}
ngOnInit() …Run Code Online (Sandbox Code Playgroud) 我是这个编码领域的新手,我认为我的问题很简单,对于像你们这些人一样有经验的人.我正在尝试为按钮内部的图像设置动画.当我点击按钮时,我需要将图像旋转360度.我不知道我在做什么错误是我的HTML和CSS代码.请帮忙
.syncRotate {
-webkit-transition: 500ms ease all !important;
-moz-transition: 500ms ease all !important;
-o-transition: 500ms ease all !important;
transition: 500ms ease all !important;
-webkit-transform: rotate(360deg) !important;
}Run Code Online (Sandbox Code Playgroud)
<button class="iconBtn" mdTooltipPosition="above" mdTooltip="Sync User" (click)="sync()">
<img class="syncRotate" style="width:20px;background-color: #a6a6a6;border-radius: 13px;padding:2px;" src="../../assets/images/icons/sync.svg" alt="Sync">
</button>Run Code Online (Sandbox Code Playgroud)
我想实现一个功能(在Angular2中),即登录后,如果用户保持浏览器空闲30分钟,则应在30分钟后返回时将其注销。这只能由前端完成。
我正在使用Angular 2.4版的angular CLI
如何在Angular2应用程序中实现此功能?
angular2-directives angular2-template angular2-services angular
在Angular 2中,我有一个带有模板的组件。
在组件TypeScript代码中,我创建了一个Reactive Extensions Observable(items$),并在ngFor带有异步管道的模板的-directive中使用它。
这样,我不必担心自己订阅和取消订阅。
<div *ngFor="let item of items$ | async"></div>
...
</div>
Run Code Online (Sandbox Code Playgroud)
现在,从组件代码中,我想访问项目列表,但不订阅它。模板是否有办法退还或引用项目列表?
我收到错误:'在角度web-app的编译时,在组件'中找不到名字'$'.当我使用const $ : any = '';然后解决了错误但在浏览器控制台中得到另一个错误:'core.js:1440 ERROR TypeError:$不是函数'并且数据表在使用时也不起作用const $ : any = '';.
下面是我的用户组件代码.此组件用于数据表的用户列表.
users.component.ts
import {DataService} from './../services/data.service';
import {Component, OnInit} from '@angular/core';
import {API_ENDPOINT} from '../app.module';
import {Response} from '@angular/http/src/static_response';
const $: any = '';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent implements OnInit {
private url = API_ENDPOINT + '/admin_api/users';
private users: any;
constructor(private dataService: DataService) {
}
ngOnInit() {
this.dataService.get(this.url)
.subscribe(responce => {
this.users = responce.data.users;
if (this.users) …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的角度应用程序使用Trix编辑器。但是,我没有任何资源/ npm软件包来在angular 2应用中安装trix编辑器。您能为我提供所需的资源/步骤吗?
angular ×9
html ×2
javascript ×2
typescript ×2
charts ×1
css ×1
npm ×1
observable ×1
rxjs ×1
trix ×1