Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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/2/ionic-framework/2.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
Angularjs 离子按钮点击不工作_Angularjs_Ionic Framework - Fatal编程技术网

Angularjs 离子按钮点击不工作

Angularjs 离子按钮点击不工作,angularjs,ionic-framework,Angularjs,Ionic Framework,我的代码非常简单。这是一个叫做“设置”的离子屏幕,它有一个叫做“每周小时数”的东西 <ion-view title="Settings"> <ion-content class="has-header"> <ul class="list"> <label class="item item-input item-label"> <span class="input-label">Hours per

我的代码非常简单。这是一个叫做“设置”的离子屏幕,它有一个叫做“每周小时数”的东西

<ion-view title="Settings">
<ion-content class="has-header">
    <ul class="list">
        <label class="item item-input item-label">
        <span class="input-label">Hours per week</span>
        <input type="text" ng-model="hoursPerWeek" value="37">
        </label>
    </ul>
    <button class="button button-balanced" ng-click="submitClicked()">
       Save
    </button>
</ion-content>
</ion-view>
从上面可以明显看出,它使用了angular本地存储模块,我已确保将其注入应用程序,如下声明所示:

angular.module('starter', ['ionic', 'starter.controllers', 'LocalStorageModule'])
问题是
submitClicked()
似乎不起作用。例如,如果我将每周小时数的值更改为42(从37改为42),它似乎适用于当前的localhost会话。当我停止服务器并再次运行它时,该值返回到37。我不知道这里出了什么问题。任何帮助都将不胜感激。我面临一个新的错误,如下面的编辑2中所述

编辑1(已修复): @冰风,这是我面临的错误

TypeError: localStorage.get is not a function
at new <anonymous> (controllers.js:45)
at Object.instantiate (ionic.bundle.js:18015)
at $controller (ionic.bundle.js:23417)
at Object.self.appendViewElement (ionic.bundle.js:59908)
at Object.render (ionic.bundle.js:57901)
at Object.init (ionic.bundle.js:57821)
at Object.self.render (ionic.bundle.js:59767)
at Object.self.register (ionic.bundle.js:59725)
at updateView (ionic.bundle.js:65400)
at ionic.bundle.js:65377

如果可用,则必须使用本地存储中的值

.controller('SettingsCtrl', function($scope, localStorageService) {
    $scope.hoursPerWeek = localStorageService.get('hoursPerWeek') || 37;
    $scope.submitClicked = function(){
        localStorageService.set('hoursPerWeek',$scope.hoursPerWeek);
    }
})

并配置喷油器以提供它。否则,您只是保存了它,并且从未使用过它。

如果可用,您必须使用本地存储中的值

.controller('SettingsCtrl', function($scope, localStorageService) {
    $scope.hoursPerWeek = localStorageService.get('hoursPerWeek') || 37;
    $scope.submitClicked = function(){
        localStorageService.set('hoursPerWeek',$scope.hoursPerWeek);
    }
})

并配置喷油器以提供它。否则,您只是保存了它,从未使用过它。

下面是我如何修复代码的。我对HTML做了一些小改动。这看起来和我问的问题差不多:

<ion-view title="Settings">
<ion-content class="has-header">
    <ul class="list">
        <label class="item item-input item-label">
        <span class="input-label">Hours per week</span>
        <input type="text" ng-model="config.hoursPerWeek">
        </label>
    </ul>
    <button class="button button-balanced" ng-click="save()">
           Save
    </button>
</ion-content>
</ion-view>
@icewind的想法实际上激发了这个答案


谢谢。

下面是我如何修复代码的。我对HTML做了一些小改动。这看起来和我问的问题差不多:

<ion-view title="Settings">
<ion-content class="has-header">
    <ul class="list">
        <label class="item item-input item-label">
        <span class="input-label">Hours per week</span>
        <input type="text" ng-model="config.hoursPerWeek">
        </label>
    </ul>
    <button class="button button-balanced" ng-click="save()">
           Save
    </button>
</ion-content>
</ion-view>
@icewind的想法实际上激发了这个答案


谢谢。

您好,先生,我试过运行您的代码,但我系统上的离子实验室似乎不喜欢这样。当我使用您的代码时,我的设置视图根本不会加载。相反,它会重定向到默认的
$urlRouterProvider.others()
视图。但是,当我将hoursPerWeek的值设置为37时,代码似乎对当前会话有效,但在停止和启动后不起作用。我不知道如何在ionic lab中检查它。我可以在chrome上打开ionic项目。您能告诉我如何检查控制台吗?如果您在chrome launch developer tools中打开它
ctrl/cmd+alt+I
这里有一个错误
TypeError:localStorage.get在Object.instantiate(ionic.bundle.js:18015)在$controller(ionic.bundle.js:23417)在Object.self.appendViewElement(ionic.bundle.js:59908)在Object.render(ionic.bundle.js:57901)在Object.init上不是函数更新视图(ionic.bundle.js:65400)的Object.self.render(ionic.bundle.js:59767)处的Object.self.register(ionic.bundle.js:59725)处的在ionic.bundle.js:65377上,您好,先生,我尝试运行您的代码,但我的系统上的ionic Lab似乎不喜欢这样。当我使用您的代码时,我的设置视图根本不会加载。它会重定向到默认的
$urlRouterProvider.Others()
我已经定义了视图。但是当我将hoursPerWeek的值设置为37时,代码似乎对当前会话有效,但在停止和启动后不起作用。我不知道如何在ionic lab中检查。我可以在chrome上打开ionic项目。您能告诉我如何检查控制台吗?如果您在chrome launch developer tools中打开它。
ctrl/cmd+alt+I
这里有一个错误
TypeError:localStorage.get在Object.instantiate(ionic.bundle.js:18015)的$controller(ionic.bundle.js:23417)在Object.self.appendViewElement(ionic.bundle.js:59908)在Object.render(ionic.bundle.js:57901)在Object.init上不是函数(ionic.bundle.js:57821)在Object.self.render(ionic.bundle.js:59767)在Object.self.register(ionic.bundle.js:59725)在updateView(ionic.bundle.js:65400)在ionic.bundle.js:65377
.controller('SettingsCtrl' , function($scope, localStorageService) {
    $scope.config = {
        hoursPerWeek: localStorage.getItem('hoursPerWeek' , 37) || 37
    };

    $scope.save = function() {
     console.log($scope.config.hoursPerWeek);
     localStorage.setItem('hoursPerWeek', $scope.config.hoursPerWeek);
    };
})