Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using angularjs $filter() inside directives

i want to hide some part of the input text value using some filter.

app.directive('limtToDate', ['$filter', function ($filter) {
var dateFormat = "DD/MM/YYYY HH:mm"
return {
    restrict: 'A',
    link: function (scope, ielem, attrs) {
        scope.$watch(attrs.ngModel, function (v) {
            console.log('value changed, new value is: ' + v);
            $filter('limitTo')(ielem.val(), -5);
        });
    }
}}]);

http://jsfiddle.net/PqAhk/2/

well, my input text should just show 12:12 instead of 01/01/1970 12:12. and after editing the time, for example, if user change the time to 12:40 my ng-model has to be like following 1970/01/01 12:40

like image 751
ziedTn Avatar asked Nov 11 '22 07:11

ziedTn


1 Answers

First, thank you all, this solution was created by @guru and many thanks to him.

http://plnkr.co/edit/VhsleIWMq8A4rJcVQDaw?p=preview

the solution takes advantage from $formatter and $parser related to the angularjs pipeline rendering.

https://docs.angularjs.org/api/ng/type/ngModel.NgModelController

ps : this solution is not compatible with angularjs.2-rc.x

like image 151
ziedTn Avatar answered Nov 14 '22 23:11

ziedTn