Angular Filter Output HTML

Source: Internet
Author: User

Write a page that shows the status (only two values 1 or 0), in order to make the page look good, when the status is 1 o'clock shows a small circle of blue color, to show a small red circle of 0 o'clock;

Start with Ngclass:

However, just display a circle, no title, the user does not know what the meaning, so instead of Directive:

App.directive (' Robotstatusclass ', function () {        return {            restrict: "A",            require: ' ^ngmodel ',            scope:{                Status: ' =ngmodel '            },            Template: ' <span class= ' Circle ' ng-class= ' class ' title= ' {{status}} ' ></span > ',            link:function (scope) {                if (scope.status = = ' 1 ') {                    scope.class = ' enabled ';                    Scope.title = ' normal ';                } else{                    scope.class = ' disabled ';                    Scope.title = ' exception ';}};    });

But the problem comes again, because the page has heartbeat package, status may change, write directive not meet the requirements, GG half a day did not solve the problem;

Finally, the filter is used to solve:

function Robotstatusclass () {        return function (input) {            if (input = = ' 1 ') {                return ' <span class= "circle Enabled "title=" normal "></span>";            } else{                return ' <span class= ' circle disabled ' title= ' exception ' ></span> ';            }        }    }

Did not expect to show is actually a string .... Finally GG found a solution:

function Robotstatusclass ($SCE) {        return function (input) {            if (input = = ' 1 ') {                return $sce. Trustas (' HTML ', ' <span class= "Circle Enabled" title= "normal" ></span> ");            } else{                return $SCE. Trustas (' HTML ', ' <span class= ' circle disabled ' title= ' exception ' ></span> ');}}}    
//
<p class= "form-control-static pull-left" ng-bind-html= "status | Robotstatusclass "></p>

  

  

Angular Filter Output HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.