How can we switch the theme in Ionic App from Lighter version to darker version ?

前端 未结 1 1115
时光说笑
时光说笑 2021-01-15 01:10

I have two CSS file generated, One for lighter Version and other for darker Version. So please let me know how can i maintain two theme for same App?

Any idea how c

相关标签:
1条回答
  • 2021-01-15 01:47

    Working plunker

    You can easily toggle between CSS files.

    index.html:

    1. set your ng-app on the HTML tag:

      <html ng-app="starter">
      
    2. dynamically set your style:

      <link ng-href="{{style}}" rel="stylesheet">
      

    app.js: define your default style in run:

    $rootScope.style = "css/style.css";
    

    controllers.js: add your toggle style logic:

    //All available styles
    $scope.styles = [
      {
        name: "Default",
        url: "style.css"
      },
      {
        name: "Dark",
        url: "dark-style.css"
      }
    ];
    
    /**
     * Change the style.
     * @param style The selected style.
     */
    $scope.changeStyle = function(style){
      $rootScope.style = "css/" + style.url;
    };
    

    view.html: attach the related HTML:

    <label class="item item-input item-select">
      <div class="input-label">
        Style
      </div>
      <select ng-options="style as style.name for style in styles" ng-change="changeStyle(style)" ng-model="style">
      </select>
    </label>
    
    0 讨论(0)
提交回复
热议问题