Unable to register A Custom angularjs filter -


i trying write own filter in angular. while trying register filter error,

error: no module: customfiltermodule

[break on error]

throw error('no module: ' + name);

angular.js (line 1090)

error: no module: myapp

[break on error]

throw error('no module: ' + name);

javascript:

angular.module('customfiltermodule') .filter('customfilter', function() {     return function(listing, param) {         var out = [];         // perform filtering logic return smaller array         return out;     }; });  var myapp = angular.module('myapp', ['customfiltermodule']);  function appcontroller($scope) {     // controller code } 

html:

    <div class="container" id="mainbody" ng-app="myapp">          <div id="listingslistbody" class="row" ng-controller="mycontroller">         ...            <div class="sub-container">               <div class="elem-box" ng-repeat="elem in elems | customfilter:jobj>               ...              </div>          </div>     </div> 

the parameter jobj pass 'customfilter' part of json object populated controller.

i can't seem figure out doing wrong.

thanks!

having live code in plunker allow people answer question in no time idea attach live code example (using plunker, jsfiddle or similar).

based on code example can spot 2 fishy things going on:

1) in code:

angular.module('customfiltermodule') .filter('customfilter', function() {     return function(listing, param) {        . . .     }; }); 

it looks trying retrieve (!) existing customfiltermodule while trying create new one. should write angular.module('customfiltermodule', []) instead (notice brackets second argument)

2) code not clear listingfilter module defined. think might problem should write:

var myapp = angular.module('myapp', ['customfiltermodule']); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -