你好我想跟踪用户添加新筹码以运行保存功能时的动作
Html:
<md-chips ng-model="contacts" md-autocomplete-snap="">
<md-autocomplete
md-selected-item="selectedItem"
md-search-text="searchText"
md-items="item in querySearch(searchText)"
md-item-text="item.name"
placeholder="Specify your reviewer(s)">
<span md-highlight-text="searchText">{{item.name}} {{item.email}}</span>
</md-autocomplete>
<md-chip-template>
<span>
{{$chip.email || $chip}}<br>
</span>
</md-chip-template>
</md-chips>
JS:
$scope.$watch('contacts', function(){
if ($scope.chip){
alert("hello")
}
})
答案 0 :(得分:1)
使用md-on-append
<md-chips md-on-append="newEmail($chip)"... >
https://github.com/angular/material/tree/master/src/components/chips/demoBasicUsage
答案 1 :(得分:0)
ng-change
会做到这一点。你可以添加:
ng-change="yourFunction()"
然后在你的控制器中
$scope.yourFunction = function(){
if ($scope.chip){
alert("hello")
}
}
这样,每当您ng-model
中的值发生变化时,此功能都会被调用。