我正在使用bootstrap进行角度下拉列表。我创建了一个指令,用户从下拉列表中选择菜单选项并提醒用户。
我在这里创建了一个plnkr
http://plnkr.co/edit/tw3O5ihT7YB79BcAGlsh?p=preview
(function() {
'use strict';
angular.module('plunker').directive('exportData', exportData);
function exportData() {
var controller = function() {
var vmd = this;
vmd.exportAction = [{
id: 1,
action: 'Export all -> excel',
visble: true
}, {
id: 2,
action: 'Export selected -> excel',
visble: true
}, {
id: 0,
action: '',
visble: true,
divider: true
}, {
id: 3,
action: 'Export all -> pdf',
visble: true
}, {
id: 4,
action: 'Export selected -> pdf',
visble: true
}];
function activate() {} //activate
activate();
vmd.selectedExport = function(action) {
alert("you selected " + action.action);
};
} //controller
return {
restrict: 'EA',
// scope: {
// datasource: '=',
// },
controller: controller,
controllerAs: 'vmd',
templateUrl: 'exportData.html',
bindToController: true
//link: function ($scope, element, attrs) {
// });
};
};
}());
任何想法,谢谢。
答案 0 :(得分:1)
您在plunkr示例http://plnkr.co/edit/YH4A5bb1o3ss5ECD0j8g
中缺少if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.') && (e.KeyChar != '-'))
{
e.Handled = true;
}
// only allow one minus -
//put condition if it is zero than only allow one minus sign
if (e.KeyChar == '-' && ((sender as TextBox).Text.IndexOf('-') > -1) && minusCount==0)
{
e.Handled = true;
//over here increment that variable
minusCount = minusCount+1;
//for handling it in middle other than zero position
if(textbox.Text.IndexOf("-")>1)
{
textbox.Text=textbox.Text.Replace("-","");
}
}