我究竟做错了什么?
import {bootstrap, Component} from 'angular2/angular2'
@Component({
selector: 'conf-talks',
template: `<div *ngFor="let talk in talks">
{{talk.title}} by {{talk.speaker}}
<p>{{talk.description}}
</div>`
})
class ConfTalks {
talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
{title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
selector: 'my-app',
directives: [ConfTalks],
template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
Run Code Online (Sandbox Code Playgroud)
错误是
EXCEPTION: Template parse errors:
Can't bind to 'ngForIn' since it isn't a known native property
("<div [ERROR ->]*ngFor="let talk in talks">
Run Code Online (Sandbox Code Playgroud) 我究竟做错了什么?
import {bootstrap, Component} from 'angular2/angular2'
@Component({
selector: 'conf-talks',
template: `<div *ngFor="talk of talks">
{{talk.title}} by {{talk.speaker}}
<p>{{talk.description}}
</div>`
})
class ConfTalks {
talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
{title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
selector: 'my-app',
directives: [ConfTalks],
template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
Run Code Online (Sandbox Code Playgroud)
错误是
EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">
Run Code Online (Sandbox Code Playgroud) 在我的Angular 2应用程序中,当我向下滚动页面并单击页面底部的链接时,它确实会更改路径并将我带到下一页但它不会滚动到页面顶部.结果,如果第一页很长而第二页的内容很少,则给人的印象是第二页缺少内容.由于只有当用户滚动到页面顶部时内容才可见.
我可以在组件的ngInit中将窗口滚动到页面顶部但是,有没有更好的解决方案可以自动处理我的应用程序中的所有路径?
typescript angular2-directives angular2-template angular2-routing angular
在这种情况下,我正在向视图中显示学生列表(数组)ngFor:
<li *ngFor="#student of students">{{student.name}}</li>
Run Code Online (Sandbox Code Playgroud)
每当我将其他学生添加到列表中时,它都会更新.
然而,当我给它一个pipe到filter由学生的名字,
<li *ngFor="#student of students | sortByName:queryElem.value ">{{student.name}}</li>
Run Code Online (Sandbox Code Playgroud)
在我在过滤学生姓名字段中输入内容之前,它不会更新列表.
这是plnkr的链接.
Hello_world.html
<h1>Students:</h1>
<label for="newStudentName"></label>
<input type="text" name="newStudentName" placeholder="newStudentName" #newStudentElem>
<button (click)="addNewStudent(newStudentElem.value)">Add New Student</button>
<br>
<input type="text" placeholder="Search" #queryElem (keyup)="0">
<ul>
<li *ngFor="#student of students | sortByName:queryElem.value ">{{student.name}}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
sort_by_name_pipe.ts
import {Pipe} from 'angular2/core';
@Pipe({
name: 'sortByName'
})
export class SortByNamePipe {
transform(value, [queryString]) {
// console.log(value, queryString);
return value.filter((student) => new RegExp(queryString).test(student.name))
// return value;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用Material 2来添加md-raised-button.
我想仅在某些条件成立时应用此指令.
例如:
<button md-raised-button="true"></button>
Run Code Online (Sandbox Code Playgroud)
另一个例子:我在plunker中创建了一个基本的动态反应形式.我正在使用formArrayName反应形式的指令来控制数组.我想formArrayName仅在特定条件成立时才应用指令.否则不添加formArrayName指令.我尝试和研究了很多,但可以找到任何解决方案.
这是plunker链接:https://plnkr.co/edit/oPZ7PyBSf8jjYa2KVh4J ? p = preview
我真的很感激任何贡献.
提前致谢!
angular-material angular2-forms angular2-directives angular-material2 angular
我有一个组件,其模板看起来像这样:
<div [my-custom-directive]>Some content here</div>
Run Code Online (Sandbox Code Playgroud)
我需要访问此处使用的MyCustomDirective类实例.当我想要访问子组件时,我使用ng.core.ViewChild查询.是否有相同的功能来访问子指令?
我有Angular组件,第一个组件使用第二个组件作为指令.它们应该共享相同的模型对象,该对象在第一个组件中初始化.如何将该模型传递给第二个组件?
我无法为Angular2找到一个好的自动完成组件.任何我可以传递一个键标签对象列表并在一个input字段上有一个很好的自动完成的东西.
剑道还不支持Angular 2,而且它是我们内部使用的.Angular Material似乎也不支持Angular 2.
任何人都可以指出我正确的方向或让我知道他们正在使用什么?
这是我到目前为止所建立的.这很糟糕,我想找一些看起来不错的东西.
import {Component, EventEmitter, Input, Output} from 'angular2/core';
import {Control} from 'angular2/common';
import {Observable} from 'rxjs/Observable';
import {SimpleKeyValue} from '../models/simple-key-value'
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
@Component({
selector: 'general-typeahead',
template: ` <div>
<div class="input-group">
<input type="text" [ngFormControl] = "term" class="form-control" placeholder={{placeHolder}} >
</div>
<ul>
<li class="item" *ngFor="#item of matchingItems" (click)="selectItem(item)">
{{item.value}}
</li>
</ul>
</div>`
})
export class GeneralTypeahead {
matchingItems: Array<SimpleKeyValue>;
term = new Control();
@Input() allItems: Array<SimpleKeyValue>;
@Input() placeHolder: string;
@Output() …Run Code Online (Sandbox Code Playgroud) 给定一个简单的输入元素,我可以这样做:
<input [(ngModel)]="name" /> {{ name }}
Run Code Online (Sandbox Code Playgroud)
这不适用于我的自定义元素:
<my-selfmade-combobox [(ngModel)]="name" values="getValues()" required></my-selfmade-combobox>
Run Code Online (Sandbox Code Playgroud)
我该如何实现它?
我有一个指令来初始化DOM元素上的jQueryUI可排序.jQueryUI sortable还有一组触发某些操作的回调事件.例如,当您启动或停止排序元素时.
我想通过函数从这样的事件传递返回参数emit(),所以我实际上可以看到我的回调函数中发生了什么.我只是没有找到通过一个传递参数的方法EventEmiiter.
我目前有以下内容.
我的指示:
@Directive({
selector: '[sortable]'
})
export class Sortable {
@Output() stopSort = new EventEmitter();
constructor(el: ElementRef) {
console.log('directive');
var options = {
stop: (event, ui) => {
this.stopSort.emit(); // How to pass the params event and ui...?
}
};
$(el.nativeElement).sortable(options).disableSelection();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我Component使用指令发生的事件:
@Component({
selector: 'my-app',
directives: [Sortable],
providers: [],
template: `
<div>
<h2>Event from jQueryUI to Component demo</h2>
<ul id="sortable" sortable (stopSort)="stopSort(event, ui)">
<li class="ui-state-default"><span …Run Code Online (Sandbox Code Playgroud)