javascript - Angular 选择不填充选项

标签 javascript angularjs node.js bootstrap-4

我正在尝试学习nodejs。我有一个简单的应用程序,我在 app.component.ts

中定义了一个数组 options
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  options = ["Option1", "Option2"];
}

我正在尝试将选项公开为下拉列表 app.component.html

<div style="text-align:center">
  <h1>
    {{options}}!
    <select name="repeatSelect" id="repeatSelect" ng-model="app-root">
      <option ng-repeat="option in options" value="{{option}}">{{option}}</option>
    </select>
  </h1>

由于某种原因,选择框没有被填充。如果我打印选项,我可以清楚地看到它打印得很好。 这是截图

enter image description here

最佳答案

您应该使用*ngFor 。因为您使用的是 Angular 4。Angular 2/4/5 中没有 ng-repeat 指令。

<option *ngFor="let option of options" value="{{option}}">{{option}}</option>

关于javascript - Angular 选择不填充选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47279513/

相关文章:

javascript - 不同页面调用不同的jQuery/JS

javascript - 向列表元素 HTML 添加空格

angularjs - Kendo Tree 列表 : sort columns based on parent element only?

javascript - Angular JS如何观看 "Only One Property"

javascript - 使用 thinky.io 连接到 compose.io rethinkDB 服务器

javascript - Axios.put 放在 Axios.get 里面

javascript - 使用 Prototype.js 检测鼠标是否正在触摸元素?

unit-testing - 具有 SignalR 依赖项的服务单元测试的 Karma 配置

javascript - 'next' 中的 'middleware function' 参数在 Node.js 的 Express 中如何工作?

javascript - 如何正确包含 jasmine-node 测试运行程序的源文件