Skip to content

Instantly share code, notes, and snippets.

@jakobloekke
Created November 4, 2013 14:25
Show Gist options
  • Select an option

  • Save jakobloekke/7303217 to your computer and use it in GitHub Desktop.

Select an option

Save jakobloekke/7303217 to your computer and use it in GitHub Desktop.

Revisions

  1. jakobloekke created this gist Nov 4, 2013.
    22 changes: 22 additions & 0 deletions ng sprintf filter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    app.filter('sprintf', function() {
    function parse(str) {
    var args = [].slice.call(arguments, 1),
    i = 0;

    return str.replace(/%s/g, function() {
    return args[i++];
    });
    }

    return function(str) {
    return parse(str, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
    };
    });


    // Usage:
    $filter('sprintf')(
    "Hello %s. It's %s to see you!",
    "World",
    "very"
    );