EasyUI Forum

General Category => General Discussion => Topic started by: azizkhani on April 17, 2015, 01:35:02 AM



Title: angular and jquery easyui ng-model
Post by: azizkhani on April 17, 2015, 01:35:02 AM
one of my big problem in ng-model.
how can set combobox or textbox or combotree  value to ng-model (two way binding)
can u give me an example?


Title: Re: angular and jquery easyui ng-model
Post by: stworthy on April 19, 2015, 07:04:09 PM
You will have to custom a directive to achieve this functionality. The code below shows a 'easyuiTextbox' directive.
Code:
var app = angular.module('myapp', []);
app.directive('easyuiTextbox', function(){
return {
restrict: 'AE',
require:'ngModel',
link: function(scope, elem, attrs, ngModel){
$(elem).textbox().textbox('textbox').bind('blur', function(){
scope.$apply(function(){
ngModel.$setViewValue($(elem).textbox('getValue'));
})
});
ngModel.$render = function(value){
$(elem).textbox('setValue', ngModel.$viewValue);
}
}
}
})

Usage example:
Code:
<body ng-app="myapp">
<input ng-model="value">
<input easyui-textbox ng-model="value" data-options="required:true"></input>
</body>