【发布时间】:2017-03-30 09:52:19
【问题描述】:
我正在尝试使用 Angular2 实现 Selectize.js,但我似乎无法使其工作。这是我在 HTML 组件中尝试过的:
<div class="form-group">
<label for="friends">Friends</label>
<input type="text" class="form-control" #friends
[(ngModel)]="user.friends" name="friends"
#picture="ngModel">
</div>
以及组件中的:
declare let $: any;
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
providers: [ AuthenticationService, UserService, MessageService ]
})
export class ProfileComponent implements OnInit, AfterViewInit {
@ViewChild('friends') el:ElementRef;
constructor(
private _userService: UserService,
private _authService: AuthenticationService,
) { }
ngAfterViewInit() {
$('#friends').selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
}
ngOnInit() {
//...
}
onSubmit(event) {
//...
}
}
所以我要做的只是在朋友输入中实现 Selectize。我希望用户能够写下他朋友的名字,然后在 Angular 中用一组名字恢复他们。
但是界面中什么也没有发生,Selectize 什么也没做。怎么会?
【问题讨论】:
标签: angular selectize.js