【发布时间】:2013-07-20 00:44:00
【问题描述】:
我正在尝试获取预先输入的结果并将其粘贴到引导警报中。我希望用户能够从预先输入的选择中多次选择,并让它创建多个引导警报。
这是我的示例。目前这两个问题是:
- 即使作为示例,警报也不起作用
-
Alert 和 Typeahead 没有互相交流
我的html:
<body ng-app="testApp">
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Choice: {{selected| json}}</pre>
<input type="text" ng-model="selected" typeahead="sample for sample in samples | filter:$viewValue">
</div>
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='btn' ng-click="addAlert()">Save Choice</button>
</div>
</body>
我的 JS:
angular.module('testApp', ['ui.bootstrap']);
function TypeaheadCtrl($scope) {
$scope.selected = undefined;
$scope.samples = ["foo","bar","blah","foobar","blahblah"];
}
function AlertDemoCtrl($scope) {
$scope.alerts = undefined;
/* $scope.alerts = [
{ type: 'error', msg: 'Oh snap! Change a few things up and try submitting again.' },
{ type: 'success', msg: 'Well done! You successfully read this important alert message.' }
];*/
$scope.addAlert = function() {
$scope.alerts.push({msg: "Another alert!"});
};
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};
}
在用户选择建议的自动完成后,用户选择的结果会显示为:{{selected| json}}。我希望该选择保留在 DOM 中,并允许用户再选择一项。然后,我想让用户能够删除选择(单击按钮或 [x])。
在我看来,实现这一点的一种方法是使用 (ui.bootstrap.alert) 记录用户的选择。
如果不使用警报也可以做到这一点,那也很好。
【问题讨论】:
标签: angularjs typeahead angular-ui-bootstrap