gpt4 book ai didi

javascript - Angular 和 Firebase 应用程序无法运行

转载 作者:行者123 更新时间:2023-11-29 10:40:45 24 4
gpt4 key购买 nike

这是我的 html:

<!DOCTYPE html>
<html ng-app="sampleApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.2/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.0.0/angularfire.min.js"></script>
<script src="scripts/app.js"></script>
</head>
<body ng-controller="SampleCtrl">
<!-- anything typed in here is magically saved to Firebase! -->
<input type="text" ng-model="data.text"/>

<!-- all changes from Firebase magically appear here! -->
<h1>You said: {{ data.text }}</h1>
</body>
</html>

这是我的 app.js 文件:

(function() {

var app = angular.module("sampleApp", ["firebase"])

app.controller("SampleCtrl", function($scope, $firebaseObject) {
var ref = new Firebase("https://fiery-inferno-4208.firebaseio.com/data");
var syncObject = $firebaseObject(ref);

syncObject.$bindTo($scope, "data");
});

})();

我从这个例子中复制了它:https://www.firebase.com/docs/web/libraries/angular/quickstart.html

当我尝试在自己的计算机上运行它时,我在控制台中收到以下错误:

未捕获的语法错误:意外的标记<

Uncaught Error :[$injector:modulerr]

我不知道哪里出了问题!

最佳答案

您的模块未被加载,因为您创建的函数从未执行过。看起来您在脚本中的最终 ; 之前缺少 () 。这为我修复了它:

(function() {

var app = angular.module("sampleApp", ["firebase"])

app.controller("SampleCtrl", function($scope, $firebaseObject) {
var ref = new Firebase("https://fiery-inferno-4208.firebaseio.com/data");
var syncObject = $firebaseObject(ref);

syncObject.$bindTo($scope, "data");
});

})();

关于javascript - Angular 和 Firebase 应用程序无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29783602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com