首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从goinstant检索存储的值

如何从goinstant检索存储的值
EN

Stack Overflow用户
提问于 2014-04-29 17:18:11
回答 1查看 89关注 0票数 3

我做错了什么。我正在尝试获取我在goinstant中存储的值。我有一间带userName的单人间。警报函数显示的值是"object Object“。下面是我的代码:(我故意遗漏了脚本)。我在goInstant上提供了个人数据的快速屏幕截图,以供参考http://screencast.com/t/BtLqfrorg

代码语言:javascript
复制
<h2>Angular JS Test</h2>
<div ng-app="testapp" data-ng-controller="personCtrl">
        <input type="text" ng-model="userName"  />{{ userName }}
        <button type="submit" id="save" name="save" >Save</button>
    <script>
        var testApp = angular.module('testapp', ['goangular']);

        testApp.config(function($goConnectionProvider) {
            $goConnectionProvider.$set('https://goinstant.net/<mykey>/test');
        });

        testApp.controller('personCtrl', function($scope, $goKey) {
            // $goKey is available

            $scope.userName = $goKey('/person/userName').$sync();
            alert($scope.userName);

        });
    </script>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-29 20:31:20

您的示例将指示您希望$scope.userName是一个基本值(一个字符串)。事实上,它是一个模型。模型为更新应用程序的状态提供了一个简单的接口,在GoAngular中,该状态自动保存到您的GoInstant应用程序中。

您可以找到关于GoAngular Model 这里的更多文档。我认为一个有用的例子可能会有帮助,所以我创建了一个柱塞script.js**:** 让我们通过

代码语言:javascript
复制
angular
  .module('TestThings', ['goangular'])
  .config(function($goConnectionProvider) {
    $goConnectionProvider.$set('https://goinstant.net/mattcreager/DingDong');
  })
  .controller('TestCtrl', function($scope, $goKey) {
    // Create a person model
    $scope.person = $goKey('person').$sync();

    // Observe the model for changes
    $scope.$watchCollection('person', function(a, b) {
      console.log('model is', a.$omit());  // Log current state of person
      console.log('model was', b.$omit()); // Log the previous state of person
    });

    // After 2000 ms set the userName property of the person model
    setTimeout(function() {
      $scope.person.$key('userName').$set('Luke Skywalker');
    }, 2000);  

    // Set the userName property of the person model
    $scope.person.$key('userName').$set('Darth Vader');
  });
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23371202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档