I am attempting to create a custom directive in Angularjs 1.4 that functions as a filter.
My goal is to restrict the length of a string using the limitTo filter within a directive instead of as a (|) filter.
Here is what I have tried so far:
charlimit.js custom directive
function controller($scope) {
$scope.length = 15;
}
angular.module('xApp')
.directive('charlimit', function () {
return {
restrict: 'A',
scope: {
limitTo: '@',
},
controller: ["$scope", controller]
};
});
index.html
<p charlimit="5"></p>
Do you have any suggestions or ideas on how to make this work correctly?
Thank you.