我尝试让firebase绑定与knockoutjs一起工作,但无法让它们工作,所以我正在尝试用angularjs进行一些测试。所以我下载了 angularjs,我试图输入/输出一些数据。所以现在我的 app.js 中有这个:
/* Controllers */
angular.module('MyCtrl3', ['$scope', 'angularFire'])
.controller ("MyCtrl3", function ($scope, angularFire) {
$scope.addMsg = function ($scope, angularFire) {
var url = 'https://kingpinapp.firebaseio.com/msgs';
var promise = angularFire(url, $scope, 'msgs', []);
$scope.msgs.push({name: "Firebase", desc: "is awesome!"});
}
});
然后我的html就是:
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
<link rel="stylesheet" href="css/bootstrap.css"/>
</head>
<body>
<div>Angular seed app: v<span app-version></span></div>
<div ng-controller="MyCtrl3">
<button ng-click="addMsg()">Add</button>
</div>
<!-- bunch of scripts -->
</body>
</html>
只是试图让添加按钮推送到firebase。我在控制台中收到此错误:Uncaught TypeError: Cannot call method 'push' of undefined。添加了一个jsfiddle:http: //jsfiddle.net/NHaZz/5/