Warning: This site describes the AngularJS (1.x) implementation of the SKY UX framework. We still support this version, but it is in maintenance mode. We no longer develop features for this version of SKY UX, and we recommend that you use the latest version instead. For more information, see developer.blackbaud.com/skyux.

Format

The format service provides access to the following functions:

  • formatText(formatString, args) — Formats the args with a given format string.
  • escape(text) — Replaces the <, >, and & HTLM characters with &lt;, &gt;, and &amp;.

Demo

Formatted result: {{formatCtrl.formattedResult}}
HTML-stripped result: {{formatCtrl.htmlResult}}

Markup

<div ng-controller="FormatServiceController as formatCtrl">
    <div class="row">
        <div class="col-md-6">
            <div class="input-group">
                <label for="formattedText">Enter some text</label>
                <input class="form-control" type="text" name="formattedText" ng-model="formatCtrl.formattedText" />
            </div>
            <div>Formatted result: {{formatCtrl.formattedResult}}</div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <div class="input-group">
                <label for="htmlText">Enter some HTML</label>
                <input class="form-control" type="text" name="htmlText" ng-model="formatCtrl.htmlText" />
            </div>
            <div>HTML-stripped result: {{formatCtrl.htmlResult}}</div>
        </div>
    </div>
</div>

JavaScript

/*global angular */

(function () {
    'use strict';

    function FormatServiceController($scope, bbFormat) {
        var self = this;

        self.formattedResult = '';
        self.formattedText = '';
        self.htmlText = '';
        self.htmlResult = '';

        $scope.$watch(function () {
            return self.formattedText;
        }, function () {
            self.formattedResult = bbFormat.formatText('[{0}]', self.formattedText);
        });

        $scope.$watch(function () {
            return self.htmlText;
        }, function () {
            self.htmlResult = bbFormat.escape(self.htmlText);
        });
    }

    FormatServiceController.$inject = ['$scope', 'bbFormat'];

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