[AngularJS] ngMessageFormat

ngMessageFormat can be installed via npm using the following command:

$ npm install angular-message-format --save

 

angular.module('myApp', ['ngMessageFormat']);

 

Pluralization with ngMessageFormat

With ngMessageFormat included, we can overload Angular expressions using a comma like this:

{{EXPRESSION, TYPE,
     =VALUE { MESSAGE }
     ...
}}

Example:

{{numberOfMessages, plural,
    =0 { You have no new messages }
    =1 { You have one new message }
    other { You have # new messages }
}}

 

{{genderExpression, select,
    male { Send him a message. }
    female { Send her a message. }
    other { Send them a message. }
}}

 

Link: http://blog.thoughtram.io/angular/2015/12/10/ng-message-format-the-unheard-feature-in-angular.html

posted @ 2015-12-21 02:07  Zhentiw  阅读(386)  评论(0编辑  收藏  举报