小编Lux*_*001的帖子

指定索引处的动态组件未正确放置

我试图在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)

typescript angular-directive angular

6
推荐指数
1
解决办法
284
查看次数

在Angular ng-if表达式中使用&(按位AND运算符)

我无法使&操作符在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(显然不使用该功能)?

javascript syntax bitwise-operators and-operator angularjs

5
推荐指数
1
解决办法
8749
查看次数

共享 Angular 库的方法不可见,即使它们应该可见

我有一个 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)

javascript shared-libraries typescript es6-modules angular

5
推荐指数
0
解决办法
49
查看次数

listview的蓝色边缘滚动线.Android的

我需要帮助才能在android上找到正确的命令来删除可滚动列表视图的蓝色边缘线.例如,这里是与图像相关的. http://imageshack.us/photo/my-images/94/immagineygv.png/ 遗憾的是,我找不到任何关于这个问题的例子,任何帮助将不胜感激.

提前致谢.

java android listview lines edge

4
推荐指数
1
解决办法
1996
查看次数