我试图用Angular2实现Selectize.js,但我似乎无法使它工作。下面是我在HTML组件已经试过:如何在Angular2中使用Selectize.js?
<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没有做任何事情。怎么来的?