md-autocomplete 上的事件侦听器?
Event Listener on md-autocomplete?
我正在 angularjs 开发应用程序并使用自动完成功能。
在此应用程序中,有些字段在自动完成选择项目之前无法填写。
这个表单中有一个字段依赖于另外两个字段的结果,如下图:
此处,Ordem、Tipo de Fluxo、Fluxo Pai 和 Descrição 字段仅在选择 UC 时才会释放。
有问题的字段是 Fluxo Pai,根据 UC 和 Tipo de Fluxo 给出的响应,选择会有所不同。
我不能简单地请求我用来过滤的 WebService,因为它没有这个过滤器,我必须使用 javascript。
I was thinking of using an event, when a UC is selected and when a Tipo de Fluxo is selected it will apply filter over filter.
提前致谢
最后,我正在使用的代码。
风景
<form name="flowRegister" ng-submit="save()">
<div layout="row">
<md-autocomplete flex required md-input-name="flowuc" md-no-cache="noCache" md-selected-item="flow.idusecase" md-search-text="searchText"
md-items="item in querySearch(searchText)" md-item-text="item.Description" md-require-match md-floating-label="UC"
md-no-asterisk>
<md-item-template>
<span>{{item.Description}} -- <strong>{{item.Aplication}}</strong> // <strong>{{item.Code}}</strong></span>
</md-item-template>
</md-autocomplete>
</div>
<div layout="row">
<div layout="column" flex="10">
<md-input-container class="md-block">
<label>Ordem</label>
<input type="number" name="flowStep" min="0" ng-model="flow.step" required data-ng-disabled="flow.idusecase == null">
</md-input-container>
</div>
<div layout="column" flex="20">
<md-input-container class="md-block">
<label>Tipo de fluxo</label>
<md-select ng-model="flow.idflowtype" required data-ng-disabled="flow.idusecase == null">
<md-option ng-repeat="flowtype in flowtypesVM" value="{{flowtype.Id}}">
{{flowtype.Description}}
</md-option>
</md-select>
</md-input-container>
</div>
<div layout="column" flex="20">
<md-input-container class="md-block">
<label>Fluxo pai</label>
<md-select ng-model="flow.idflowinitial" required data-ng-disabled="flow.idflowtype == 1 || flow.idusecase == null">
<md-option value="0" selected>
Nenhum
</md-option>
<md-option ng-repeat="flowtype in flowtypes" value="{{flowtype.Id}}">
{{flowtype.Description}}
</md-option>
</md-select>
</md-input-container>
</div>
<div layout="column" flex="60">
<md-input-container class="md-block">
<label>Descrição</label>
<input type="text" name="flowDesc" ng-model="flow.desc" required data-ng-disabled="flow.idusecase == null">
</md-input-container>
</div>
<div layout="column" flex="10" layout-align="top center">
<md-button type="submit" class="md-fab md-primary md-hue-2 md-mini" aria-label="Profile">
<md-icon md-font-set="material-icons">add</md-icon>
</md-button>
</div>
</div>
控制器
app
.controller('flCtrl', function ($rootScope, $scope, $flow, $flowtype, $usecase, $timeout, $q) {
$rootScope.menu = "Cadastro de Flow";
$scope.flow = { id: 0, usercreate: "app.outros" };
// $scope.usecases = loadAll();
$usecase.load(function (usecases) {
$scope.usecases = usecases.result;
}, function (err) {
console.log(err);
});
// console.log($scope.usecases);
$scope.selectedItem = null;
$scope.searchText = null;
$scope.querySearch = querySearch;
$flowtype.load(function (flowtypes) {
$scope.flowtypesVM = flowtypes.result;
}, function (err) {
console.log(err);
});
$flow.load(function (flowsvm) {
$scope.flowsvm = flowsvm;
}, function (err) {
console.log(err);
});
$scope.usecaseflows = [];
$scope.save = function () {
// alert("Olá");
var flow = $scope.flow;
flow.idusecase = $scope.flow.idusecase.Id;
var param = [flow];
$flow.save(param)
.then(function (resolve) {
alert("Ok!");
$scope.flowRegister.$setPristine();
document.flowRegister.reset();
})
.catch(function (reject) {
})
}
function querySearch(query) {
var results = query ? $scope.usecases.filter(createFilterFor(query)) : $scope.usecases;
return results;
}
function createFilterFor(query) {
return function filterFn(usecases) {
return (usecases.Description.indexOf(query) === 0);
};
}
});
我想你可以这样做:
app.controller('flCtrl', function ($rootScope, $scope, $flow, $flowtype, $usecase, $timeout, $q) {
...
$scope.$watch('flow', function(){
if(flow.idflowtype && flow.idusecase) {
// call apply filter function here
}
})
})
我正在 angularjs 开发应用程序并使用自动完成功能。
在此应用程序中,有些字段在自动完成选择项目之前无法填写。
这个表单中有一个字段依赖于另外两个字段的结果,如下图:
此处,Ordem、Tipo de Fluxo、Fluxo Pai 和 Descrição 字段仅在选择 UC 时才会释放。
有问题的字段是 Fluxo Pai,根据 UC 和 Tipo de Fluxo 给出的响应,选择会有所不同。
我不能简单地请求我用来过滤的 WebService,因为它没有这个过滤器,我必须使用 javascript。
I was thinking of using an event, when a UC is selected and when a Tipo de Fluxo is selected it will apply filter over filter.
提前致谢
最后,我正在使用的代码。
风景
<form name="flowRegister" ng-submit="save()">
<div layout="row">
<md-autocomplete flex required md-input-name="flowuc" md-no-cache="noCache" md-selected-item="flow.idusecase" md-search-text="searchText"
md-items="item in querySearch(searchText)" md-item-text="item.Description" md-require-match md-floating-label="UC"
md-no-asterisk>
<md-item-template>
<span>{{item.Description}} -- <strong>{{item.Aplication}}</strong> // <strong>{{item.Code}}</strong></span>
</md-item-template>
</md-autocomplete>
</div>
<div layout="row">
<div layout="column" flex="10">
<md-input-container class="md-block">
<label>Ordem</label>
<input type="number" name="flowStep" min="0" ng-model="flow.step" required data-ng-disabled="flow.idusecase == null">
</md-input-container>
</div>
<div layout="column" flex="20">
<md-input-container class="md-block">
<label>Tipo de fluxo</label>
<md-select ng-model="flow.idflowtype" required data-ng-disabled="flow.idusecase == null">
<md-option ng-repeat="flowtype in flowtypesVM" value="{{flowtype.Id}}">
{{flowtype.Description}}
</md-option>
</md-select>
</md-input-container>
</div>
<div layout="column" flex="20">
<md-input-container class="md-block">
<label>Fluxo pai</label>
<md-select ng-model="flow.idflowinitial" required data-ng-disabled="flow.idflowtype == 1 || flow.idusecase == null">
<md-option value="0" selected>
Nenhum
</md-option>
<md-option ng-repeat="flowtype in flowtypes" value="{{flowtype.Id}}">
{{flowtype.Description}}
</md-option>
</md-select>
</md-input-container>
</div>
<div layout="column" flex="60">
<md-input-container class="md-block">
<label>Descrição</label>
<input type="text" name="flowDesc" ng-model="flow.desc" required data-ng-disabled="flow.idusecase == null">
</md-input-container>
</div>
<div layout="column" flex="10" layout-align="top center">
<md-button type="submit" class="md-fab md-primary md-hue-2 md-mini" aria-label="Profile">
<md-icon md-font-set="material-icons">add</md-icon>
</md-button>
</div>
</div>
控制器
app
.controller('flCtrl', function ($rootScope, $scope, $flow, $flowtype, $usecase, $timeout, $q) {
$rootScope.menu = "Cadastro de Flow";
$scope.flow = { id: 0, usercreate: "app.outros" };
// $scope.usecases = loadAll();
$usecase.load(function (usecases) {
$scope.usecases = usecases.result;
}, function (err) {
console.log(err);
});
// console.log($scope.usecases);
$scope.selectedItem = null;
$scope.searchText = null;
$scope.querySearch = querySearch;
$flowtype.load(function (flowtypes) {
$scope.flowtypesVM = flowtypes.result;
}, function (err) {
console.log(err);
});
$flow.load(function (flowsvm) {
$scope.flowsvm = flowsvm;
}, function (err) {
console.log(err);
});
$scope.usecaseflows = [];
$scope.save = function () {
// alert("Olá");
var flow = $scope.flow;
flow.idusecase = $scope.flow.idusecase.Id;
var param = [flow];
$flow.save(param)
.then(function (resolve) {
alert("Ok!");
$scope.flowRegister.$setPristine();
document.flowRegister.reset();
})
.catch(function (reject) {
})
}
function querySearch(query) {
var results = query ? $scope.usecases.filter(createFilterFor(query)) : $scope.usecases;
return results;
}
function createFilterFor(query) {
return function filterFn(usecases) {
return (usecases.Description.indexOf(query) === 0);
};
}
});
我想你可以这样做:
app.controller('flCtrl', function ($rootScope, $scope, $flow, $flowtype, $usecase, $timeout, $q) {
...
$scope.$watch('flow', function(){
if(flow.idflowtype && flow.idusecase) {
// call apply filter function here
}
})
})