我正尝试创建一个angular-ui-bootstrap警报,其中超时值是以编程方式设置的。我阅读了angular-ui docs中的超时解雇属性。我可以为变量设置angular-ui警报超时吗?
这似乎工作:
<uib-alert ng-repeat="alert in alerts" dismiss-on-timeout=5000 type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>
不过,我能做到以下几点,使用一个变量?它似乎并没有工作:(
<uib-alert ng-repeat="alert in alerts" dismiss-on-timeout="{{alert.timeout}}" type="{{alert.type}}" close="closeAlert($index)" >{{alert.msg}}</uib-alert>
控制器:
angular.module('ui.bootstrap.demo').controller('AlertDemoCtrl', function ($scope) {
$scope.alerts = [
{ type: 'danger', timeout: 5000, msg: 'Oh snap! Change a few things up and try submitting again.' },
{ type: 'success', timeout: 5000, 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);
};
});
看看你写的东西好像没什么不对。你可以发布控制器和'alert'的定义吗? –
@RicardoVelhote这样做:)它是来自文档的控制器,超时添加到警报。 –
嗯,我认为现在调用“alert.type”还为时过早,因为你和ng-repeat在同一行。也许创建一个全局变量或第二个Controller到你的“body”标签并在那里首先创建一个超时。 –