我正在尝试创建一个angular-ui-bootstrap警报,其中以编程方式设置超时。我在angular-ui docs中读到了关于超时消除属性的信息。
这似乎有效:
<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);
};
});
答案 0 :(得分:0)
我们走了:
UI-自举-TPLS-0.14.2.js:
angular.module('ui.bootstrap.alert', [])
.controller('UibAlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) {
$scope.closeable = !!$attrs.close;
debugger;
if (angular.isDefined($scope.dismissOnTimeout)) {
$timeout(function() {
$scope.close();
}, parseInt($scope.dismissOnTimeout, 10));
}
}])
.directive('uibAlert', function() {
return {
controller: 'UibAlertController',
controllerAs: 'alert',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/alert/alert.html';
},
transclude: true,
replace: true,
scope: {
type: '@',
close: '&',
dismissOnTimeout: '=',
},
link: function link(scope, element, attrs) {
debugger;
console.log("link");
}
};
});
在你的&#34; app.js&#34;添加到&#34; AlertController&#34;:
$scope.timeout = 1000;
在您的HTML文件中:
<uib-alert ng-repeat="alert in alerts" dismiss-on-timeout="timeout" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}, {{alert.timeout}}</uib-alert>
我从angularjs分叉了demo plunkr并添加了我自己的angular-ui-bootstrap代码...... Here