Angularjs md芯片不与md自动完成一起工作
我正在尝试在芯片中嵌入自动完成的代码片段。但从自动完成中选择的项目不会转换为芯片 自动完成的数据如下所示:Angularjs md芯片不与md自动完成一起工作,angularjs,autocomplete,angular-material,Angularjs,Autocomplete,Angular Material,我正在尝试在芯片中嵌入自动完成的代码片段。但从自动完成中选择的项目不会转换为芯片 自动完成的数据如下所示: {name:“John Doe”,id:“1”} 请告诉我哪里错了 问候 这是我的芯片代码: <md-chips ng-model="student_ex" md-autocomplete-snap md-transform-chip="transformChip($chip)" md-require-match flex> <md
{name:“John Doe”,id:“1”}
请告诉我哪里错了
问候
这是我的芯片代码:
<md-chips ng-model="student_ex"
md-autocomplete-snap
md-transform-chip="transformChip($chip)"
md-require-match flex>
<md-autocomplete flex
md-selected-item="student"
md-search-text="searchText"
md-items="item in searchStudent(searchText)"
md-item-text="item.name"
placeholder="Search for a Student to Exclude">
<span md-highlight-text="searchText">ID: {{ item.id }} | Name: {{ item.name }}</span>
</md-autocomplete>
<md-chip-template>
<span>
<strong>{{$chip}}</strong><em></em>
</span>
</md-chip-template>
</md-chips>
初始化模型,如下所示:
$scope.student_ex = [];
angular.module('MyApp',['ngMaterial'])。controller('AppCtrl',function($scope){
$scope.student_list=$scope.student_list=[{name:“John Doe”,id:“1”},{name:“Antipod”,id:“2”}];
$scope.student_ex=[];
$scope.searchStudent=函数(查询){
如果(/^\d+$/.test(查询))){
var结果=查询?$scope.student\u list.filter(
功能(名称){
var regex=newregexp(查询,'gi');
返回name.id.match(regex);
}
):$scope.student_列表;
}否则{
var结果=查询?$scope.student\u list.filter(
功能(名称){
var lowercasequaly=angular.lowercase(查询);
var regex=new RegExp(小写字母,gi');
返回name.name.match(regex);
}
):$scope.student_列表;
}
返回结果;
};
$scope.transformChip=功能(芯片){
返回芯片;
}
});代码>
ID:{item.ID}}名称:{{item.Name}
{{$chip.name}
忘记添加:返回错误:错误:this.items未定义MdChipsCtrl.prototype。appendChip@http://localhost/api/api/api/web/js/angular material.js:20754:9
这相当简单。谢谢。嗯,我想说修复方法很简单,但找到它确实需要时间。我很高兴这有帮助,我理解这一点。我在这里发布之前浪费了两个小时。因此我感到惊讶P谢谢你的时间,伙计!:谢谢你发这个帖子!如果未定义,它应该绝对初始化数组。。。像其他所有组件一样。。。
$scope.student_ex = [];