我做错了什么。我正在尝试获取我在goinstant中存储的值。我有一间带userName的单人间。警报函数显示的值是"object Object“。下面是我的代码:(我故意遗漏了脚本)。我在goInstant上提供了个人数据的快速屏幕截图,以供参考http://screencast.com/t/BtLqfrorg
<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>发布于 2014-04-29 20:31:20
您的示例将指示您希望$scope.userName是一个基本值(一个字符串)。事实上,它是一个模型。模型为更新应用程序的状态提供了一个简单的接口,在GoAngular中,该状态自动保存到您的GoInstant应用程序中。
您可以找到关于GoAngular Model 这里的更多文档。我认为一个有用的例子可能会有帮助,所以我创建了一个柱塞。script.js**:** 让我们通过
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');
});https://stackoverflow.com/questions/23371202
复制相似问题