Utilities

The SKY UX utilities module provides the following Angular filters:

  • encodeURIComponent — Uses the $window.encodeURIComponent function on your string.
  • format — Formats the args with a given format string.

Demo

Formatted result is: {{'*{0}{0}*' | format:utilCtrl.formattedText}}
Encoded result is: {{utilCtrl.encodedText | encodeURIComponent}}

Markup

<div ng-controller="UtilitiesController as utilCtrl">
    <div class="row">
        <div class="col-md-6">
            <div class="input-group">
                <label for="formatFilter">Enter some text</label>
                <input class="form-control" type="text" name="formatFilter" ng-model="utilCtrl.formattedText" />
            </div>
            <div>Formatted result is: {{'*{0}{0}*' | format:utilCtrl.formattedText}}</div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <div class="input-group">
                <label for="encodeURIFilter">Enter URI to encode</label>
                <input class="form-control" type="text" name="encodeURIFilter" ng-model="utilCtrl.encodedText" />
            </div>
            <div>Encoded result is: {{utilCtrl.encodedText | encodeURIComponent}}</div>
        </div>
    </div>
</div>

JavaScript

/*global angular */
(function () {
    'use strict';

    function UtilitiesController() {
        var self = this;

        self.formattedText = '';
        self.encodedText = 'amp=&';
    }

    angular.module('stache').controller('UtilitiesController', UtilitiesController);
}());