我正在尝试将text中的事件绑定到textbox.But由于某种原因它不会触发 这是我的指示
angular.module('ui.event',[]).directive('uiEvent', ['$parse',
function ($parse) {
return function ($scope, elm, attrs) {
var events = $scope.$eval(attrs.uiEvent);
angular.forEach(events, function (uiEvent, eventName) {console.log("hi");
var fn = $parse(uiEvent);
elm.bind(eventName, function (evt) {
console.log("hi1");
var params = Array.prototype.slice.call(arguments);
//Take out first paramater (event object);
params = params.splice(1);
fn($scope, {$event: evt, $params: params});
if (!$scope.$$phase) {
console.log("hi3");
$scope.$apply();
}
});
});
};
}]);
这是控制器
$scope.changeClass = function (options) {
var widget = options.methods.widget();
// remove default class, use bootstrap style
widget.removeClass('ui-menu ui-corner-all ui-widget-content').addClass('dropdown-menu');
};
$scope.myOption = {
options: {
html: true,
minLength: 1,
onlySelectValid: true,
outHeight: 50,
source: function (request, response) {
var data = [
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
data = $scope.myOption.methods.filter(data, request.term);
if (!data.length) {
data.push({
label: 'not found',
value: null
});
}
// add "Add Language" button to autocomplete menu bottom
data.push({
label: $compile('<a class="ui-menu-add" ng-click="add()">Add Language</a>')($scope),
value: null
});
response(data);
}
},
events: {
change: function (event, ui) {
console.log('change', event, ui);
},
select: function (event, ui) {
console.log('select', event, ui);
}
}
};
$scope.add = function () {
alert('You can do some thing!');
};
这里是html
<input style="width: 200px" ng-model="modelObj" ui-event="{autocompletecreate:'changeClass(myOption)'}" ui-autocomplete="myOption">
我在app模块中使用指令模块,但事件没有绑定 任何可能出错的建议