小编Adr*_*rma的帖子

Angular ViewChild fileInput 注释未定义

如果我的 fileInput 元素位于普通 div 中,那么它可以正常工作。但如果我把它放在里面<ng-template></ng-template>那么我就会得到它的未定义。

这是我的代码:

超文本标记语言

<ng-template #content let-c="close" let-d="dismiss">
   <div class="modal-header">
      <h4 class="modal-title">Modal title</h4>
      <button type="button" class="close" aria-label="Close" (click)="d('Cross click')"></button>
   </div>
   <div class="modal-body">
      <form #documentsForm="ngForm" (ngSubmit)="onEditSubscriberDocumentsSubmit(documentsForm.value);documentsForm.reset()">
         <input #fileInput type="file" #select name="document" [(ngModel)]="document" (click)="onDocUpload()" />       
         <input type="submit" value="Save" class="btn btn-success" [hidden]="addDocHidden">
      </form>
   </div>
   <div class="modal-footer">
      <button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
   </div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)

TS

import { Component, OnInit, ViewChild , ElementRef} from '@angular/core';

export class EditSubscriberComponent {
    constructor(private http: Http, private route: ActivatedRoute, private router: Router, private …
Run Code Online (Sandbox Code Playgroud)

typescript angularjs-ng-template ng-template viewchild angular

2
推荐指数
1
解决办法
6428
查看次数

Angular 4 在 &lt;td&gt; 中调用函数

我有这段代码:

人员列表组件.html

<tr *ngFor="let person of personService.getPersons()">
      <td (onShow)="getCountry(person)">{{person.name}}</td>
      <td>{{country}}
</tr
Run Code Online (Sandbox Code Playgroud)

personListComponent.ts

<tr *ngFor="let person of personService.getPersons()">
      <td (onShow)="getCountry(person)">{{person.name}}</td>
      <td>{{country}}
</tr
Run Code Online (Sandbox Code Playgroud)

我想从这个人那里得到国家并将它显示在表格中,但是(onShow)从不调用getCountry()函数。有没有办法从<td>元素内部调用这个函数?或者有什么方法可以显示国家?

html typescript angular

2
推荐指数
1
解决办法
6535
查看次数

将数组显示为分页视图

我正在尝试使用 Angular PPT 视图页面来显示对象数组ngFor。为此,我准备了一个临时对象,它工作正常,我能够将其显示为页面。

临时对象:

let data = [
      {
        "page": "page1",
        "data": [
          {
            "id": "1",
            "content": "abc",
            "checked": true
          },
          {
            "id": "2",
            "content": "xyz",
            "checked": true
          }
        ]
      },
      {
        "page": "page2",
        "data": [
          {
            "id": "3",
            "content": "abc",
            "checked": true
          },
          {
            "id": "4",
            "content": "xyz",
            "checked": true
          }
        ]
      }
    ]
Run Code Online (Sandbox Code Playgroud)

但是,使用我的原始数组,我无法转换为相同的格式

原始数组

[
  {
    "id": 1,
    "content": "abc"
  },
   {
    "id": 2,
    "content": "xyz"
  },
   {
    "id": 3,
    "content": "xyz"
  },
   { …
Run Code Online (Sandbox Code Playgroud)

javascript angular

2
推荐指数
1
解决办法
218
查看次数

如何让component.ts在加载模板之前加载所有响应?

我想从component.ts文件中的函数加载所有响应,然后让模板查看该数据。

我的函数中有3个函数,ngOnInit这些响应使我可以将其加载到模板中。

    ngOnInit() {
        this.getSong();
        this.getAllSongs();
        this.getProjects();
    }

    // get Latest Song
    getSong() {
        this.amen.getSongs(this.singleSongParam).subscribe(
            (response) => {
                this.handleSongResponse(response);
            },
            (error) => {
                this.error = error.error.errors;
            }
        );
    }

    getAllSongs() {
        this.amen.getSongs(this.allSongsParam).subscribe(
            (response) => {
                this.handleSongsResponse(response);
            },
            (error) => {
                this.error = error.error.errors;
            }
        );
    }

    getProjects() {
        this.amen.getProjects(this.projectsParam).subscribe(
            (response) => {
                this.handleProjectsResponse(response);
            },
            (error) => {
                this.error = error.error.errors;
            }
        );
    }
Run Code Online (Sandbox Code Playgroud)

也许我async/await在订阅中使用但不知道如何使用...如果有任何方法可以帮助您。

angular

2
推荐指数
1
解决办法
64
查看次数

Angular(2/4)modalService.close()无法正常工作

这是我的代码:

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

constructor(private http: Http, private route: ActivatedRoute,private router: Router, private modalService: NgbModal) { }

editDocumentRow = function (documentId, modal) {
    this.http.get(ConstantComponent.url + '/documentmanagerapi/Get/' + documentId).map((res: Response) => res.json()).subscribe(data => {
    this.documentsRowDetails = data
    this.modalService.open(modal)
    this.modalService.close() // not working
})
Run Code Online (Sandbox Code Playgroud)

}

我试图 this.modalService.close()在其他功能中使用。但是它甚至不能在相同的功能下工作this.modalService.open(modal)完美运行。

我收到此错误: this.modalService.close is not a function

有什么建议吗?

bootstrap-modal viewchild angular

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

如何在 Angular 6 中使用 microsoft office-js 定义 Excel

我正在关注这个网站来集成office js

像这样声明:

import * as Excel from '@microsoft/office-js/excel' 它显示编译时错误:

找不到模块“@microsoft/office-js/excel”

像这样声明:

declare var Excel: any

它显示运行时错误:

错误 ReferenceError:Excel 未定义

请建议如何申报。我需要像这样使用它:

Excel.run(session, (context){
   ...
});
Run Code Online (Sandbox Code Playgroud)

office-addins typescript office-js angular office-js-helpers

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

为什么我的角度代码无法在屏幕上呈现任何内容

我有一个输入字段。我想在屏幕上实时打印我输入的任何内容。

下面的代码在输入字段中显示“ Hello world”。但不执行任何实时绑定。

档案:app.component.html

<h1>Hello world</h1>
<input type="text">
Run Code Online (Sandbox Code Playgroud)

但是那一刻我补充[(ngModule)]。一切都消失了,甚至是Hello世界。虽然cmd提示说编译成功。

<h1>Hello world</h1>
<input type="text" [(ngModel)]="name">
<p>{{ name }}</p>
Run Code Online (Sandbox Code Playgroud)

我的app.component.ts文件是:

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  name = '';
}
Run Code Online (Sandbox Code Playgroud)

为了方便起见,我还将代码上传到了GitHub

angular

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

在新元素中合并两个数组元素

我有两个数组。

 $a = ['0' => 1, '1' => 2, '2' => 3]
 $b = ['0' => 4, '1' => 5, '2' => 6]
Run Code Online (Sandbox Code Playgroud)

我想像这样创建新的数组

 $c = [['a' => 1, 'b' => '4'], ['a' => '2', 'b' => '5']]
Run Code Online (Sandbox Code Playgroud)

我已经尝试了这些功能array_merge,array_merge_recursive但没有得到积极的结果

$data = array_merge_recursive(array_values($urls), array_values($id));
Run Code Online (Sandbox Code Playgroud)

php laravel

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

如何在有角度的html页面中添加动态颜色

如果我尝试在 div 标签中添加它。 <div>{{list.color_code}}</div>

那么它的完美工作但是当我尝试这个内联css时,它不会反映在浏览器的inspect元素上。样式标签在检查元素中保持为空style = "";

我正在使用以下语法。

<div style="background:{{list.color_code}}">Hello</div>
Run Code Online (Sandbox Code Playgroud)

ionic3 angular

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

使用 Autofixture C# 创建具有特定值的列表

该模型具有属性等Id。Code

我想用特定的不同代码创建 4 个数据。

 var data = _fixture.Build<MyModel>()
                .With(f => f.Code, "A")
                .CreateMany(4);
Run Code Online (Sandbox Code Playgroud)

这将产生所有 4 个数据均带有代码“A”。我想要 4 个数据的代码为“A”、“B”、“C”、“D”

提前致谢

c# xunit autofixture

1
推荐指数
2
解决办法
6450
查看次数