我試圖用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沒有做任何事情。怎麼來的?