Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何允许用户在ionic中更改应用程序背景色_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 如何允许用户在ionic中更改应用程序背景色

Javascript 如何允许用户在ionic中更改应用程序背景色,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,如何允许用户在ionic中使用Angular更改应用程序颜色。例如,我想创建一个按钮,当它被单击时,它应该带来一个颜色下拉列表,当选择一种颜色时,它应该更改您可以使用的应用程序背景色 将ng click=“selectTheme()”添加到您的按钮,并声明如下: .controller('yourCtrl', function($scope, $ionicPopup) { $scope.selectTheme = function() { $ionicPopup.show

如何允许用户在ionic中使用Angular更改应用程序颜色。例如,我想创建一个按钮,当它被单击时,它应该带来一个颜色下拉列表,当选择一种颜色时,它应该更改您可以使用的应用程序背景色

ng click=“selectTheme()”
添加到您的按钮,并声明如下:

.controller('yourCtrl', function($scope, $ionicPopup) {
    $scope.selectTheme = function() {
        $ionicPopup.show({
            title: 'Select Theme',
            templateUrl: 'templates/select-theme.html',
            scope: $scope,
            buttons: [{ text: 'Ok' }],
        });
    });
    $scope.themes = [
        { name: 'Theme 1', color: '#f00' },
        { name: 'Theme 2', color: '#0f0' },
        { name: 'Theme 3', color: '#00f' },
        { name: 'Theme 4', color: '#ff0' },
        { name: 'Theme 5', color: '#0ff' },
    ];
    $scope.changeTheme = function (theme) {
        $scope.bgColor = theme;
    };
    $scope.bgColor = $scope.themes[0]; // initial theme
})
然后,您可以创建一个列表,在
模板/select theme.html
中选择颜色:

<div class="list card">
    <div class="item" ng-repeat="theme in themes" ng-click="changeTheme(theme)">
        <div class="color-ball" style="background-color:{{theme.color}}"></div>
        <h2 ng-bind="theme.name"></h2>
        <p ng-if="theme === bgColor">(Selected)</p>
    </div>
</div>
然后,您只需要在
中设置
style=“background color:{{{{bgColor.color}}”

希望有帮助。

您可以使用

ng click=“selectTheme()”
添加到您的按钮,并声明如下:

.controller('yourCtrl', function($scope, $ionicPopup) {
    $scope.selectTheme = function() {
        $ionicPopup.show({
            title: 'Select Theme',
            templateUrl: 'templates/select-theme.html',
            scope: $scope,
            buttons: [{ text: 'Ok' }],
        });
    });
    $scope.themes = [
        { name: 'Theme 1', color: '#f00' },
        { name: 'Theme 2', color: '#0f0' },
        { name: 'Theme 3', color: '#00f' },
        { name: 'Theme 4', color: '#ff0' },
        { name: 'Theme 5', color: '#0ff' },
    ];
    $scope.changeTheme = function (theme) {
        $scope.bgColor = theme;
    };
    $scope.bgColor = $scope.themes[0]; // initial theme
})
然后,您可以创建一个列表,在
模板/select theme.html
中选择颜色:

<div class="list card">
    <div class="item" ng-repeat="theme in themes" ng-click="changeTheme(theme)">
        <div class="color-ball" style="background-color:{{theme.color}}"></div>
        <h2 ng-bind="theme.name"></h2>
        <p ng-if="theme === bgColor">(Selected)</p>
    </div>
</div>
然后,您只需要在
中设置
style=“background color:{{{{bgColor.color}}”


希望有帮助。

请让我知道我的答案是否对您有效。请让我知道我的答案是否对您有效。