我试图在Angular中显示一个简单的项目列表,侧面有一个可点击的div; 在用户选择时,组件应在单击的组件下方动态创建新组件.
为此目的,我使用ComponentFactoryResolver没有相关问题; 但是,使用ViewContainerRefas parent,我无法找到如何将创建的组件放在指定的索引处,即使我将其指定为createComponent()方法中的参数也是如此.
app.component.html
<h3>Click on the arrow to create a component below the item clicked.</h3>
<div #myContainer>
<div *ngFor="let thing of things; let index = index">
<div class="inline click" (click)="thingSelected(thing, index)"> > </div>
<div class="inline">{{thing.id}}</div>
<div class="inline">{{thing.name}}</div>
<div class="inline">{{thing.value}}</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
app.component.ts
export class AppComponent {
@ViewChild('myContainer', { read: ViewContainerRef }) container: ViewContainerRef;
things = [];
constructor(private componentFactoryResolver: ComponentFactoryResolver){
for(let i=0; i < 10; i++)
this.things.push({id: i, name: "thing" + i, …Run Code Online (Sandbox Code Playgroud) 我无法使&操作符在Angular ng-if表达式中工作(与一些位标志一起使用).假设我们有这样的HTML:
<div ng-if="value & 2"> </div>
Run Code Online (Sandbox Code Playgroud)
如果value等于3,则按位运算应返回2,因此返回真值.
但是,Angular Syntax Error每次都会抛出一个异常.操作不被允许吗?或者我做错了什么?
链接到plunker.
编辑:我已经通过使用一个简单的函数解决了我的问题:
$scope.checkFlag = function(value, flag){
return value & flag;
}
Run Code Online (Sandbox Code Playgroud)
但我真的不喜欢这个解决方案.有没有办法在它中使用它ng-if(显然不使用该功能)?
我有一个 Angular 11 应用程序,它使用了我自己编写的一些 Angular 库;其中一些彼此之间存在依赖关系,如下图所示:
ServiceA.ts(捆绑FeatureA):
import { Injectable } from '@angular/core';
@Injectable()
export class ServiceA {
constructor() { }
method1() {
return 'method1';
}
method2() {
return 'method2';
}
}
Run Code Online (Sandbox Code Playgroud)
ServiceB.ts(捆绑FeatureB):
import { Injectable } from '@angular/core';
import { ServiceA } from '@my-lib/some-lib/src/lib/featureA';
@Injectable()
export class ServiceB extends ServiceA { // Here i extend ServiceA, to inherit method1 and method2
constructor() {
super();
}
method3() {
return 'method3';
}
metodo4() {
return …Run Code Online (Sandbox Code Playgroud) 我需要帮助才能在android上找到正确的命令来删除可滚动列表视图的蓝色边缘线.例如,这里是与图像相关的. http://imageshack.us/photo/my-images/94/immagineygv.png/ 遗憾的是,我找不到任何关于这个问题的例子,任何帮助将不胜感激.
提前致谢.
angular ×2
javascript ×2
typescript ×2
and-operator ×1
android ×1
angularjs ×1
edge ×1
es6-modules ×1
java ×1
lines ×1
listview ×1
syntax ×1