How to set text color in Angular-Material?

前端 未结 9 1542
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 19:20

I want to set one word in a sentence to have md-primary color, and another word to have the accent color. I assumed something like this:

Hel
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 19:34

    EDITED 2015/07/23

    TitForTat's comment has better solution https://github.com/angular/material/issues/1269#issuecomment-121303016


    I created a module:

    (function () {
            "use strict";
            angular
                .module('custiom.material', ['material.core'])
                .directive('cMdThemeFg', ["$mdTheming", function ($mdTheming) {
                    return {
                        restrict: 'A',
                        link: postLink
                    };
                    function postLink(scope, element, attr) {
                        $mdTheming(element);
                        element.addClass('c-md-fg');
                    }
    
                }])
                .directive('cMdThemeBg', ["$mdTheming", function ($mdTheming) {
                    return {
                        restrict: 'A',
                        link: postLink
                    };
                    function postLink(scope, element, attr) {
                        $mdTheming(element);
                        element.addClass('c-md-bg');
                    }
                }]);
        })();
    

    and then append

    .c-md-fg.md-THEME_NAME-theme.md-primary {    color: '{{primary-color}}'; }
    .c-md-fg.md-THEME_NAME-theme.md-accent {    color: '{{accent-color}}'; } 
    .c-md-fg.md-THEME_NAME-theme.md-warn {    color: '{{warn-color}}'; } 
    .c-md-bg.md-THEME_NAME-theme.md-primary {    background-color: '{{primary-color}}'; } 
    .c-md-bg.md-THEME_NAME-theme.md-accent {    background-color: '{{accent-color}}'; } 
    .c-md-bg.md-THEME_NAME-theme.md-warn {    background-color: '{{warn-color}}'; }
    

    into angular-material.js at 13783 line

    angular.module("material.core").constant("......  HERE")
    

    Then, I can simply apply c-md-theme-fg and/or c-md-theme-bg to element to apply theme colors. Like this:

    dasdasdasd
    test

    It works.

    ps: sorry about english, come from Taiwan :)

提交回复
热议问题