【发布时间】:2017-11-29 05:50:30
【问题描述】:
我的 Angular js 有问题,它会给我这个错误print screen of the error in the console log
我正在尝试通过 firebase 检索用户名,然后使用 angular js 将其打印到网页上。
这是我的 html 中的代码
<header>
<div class="header-content">
<div class="header-content-inner">
<!--<h1 id="homeHeading">Your Favorite Source of Free Bootstrap Themes</h1>!-->
<div data-ng-app="myApp" data-ng-controller="myCtrl">//fix this
<p>welcome, {{firstname}}</p>
<hr>
<p>Start Bootstrap can help you build better websites using the Bootstrap CSS framework! Just download your template and start going, no strings attached!</p>
<a href="#about" class="btn btn-primary btn-xl page-scroll">Find Out More</a>
</div>
</div>
</div>
</header>
这是我的javascript
<script>
$(document).ready(function(){
var app = angular.module('myApp',['ngRoute']);
app.controller('myCtrl', function($scope){
var userId = firebase.auth().currentUser.uid;
console.log(userId);
$scope.firstname = firebase.database().ref('users/' + userId).once('value').then(function(snapshot){
console.log(snapshot.val().firstname);
return snapshot.val().firstname;
});
});
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser){
console.log(firebaseUser);
}else{
window.location.replace("index.html");
console.log('not logged in');
}
});
$("#btnLogout").click(function(){
firebase.auth().signOut();
window.location.replace("index.html");
});
});
</script>
【问题讨论】:
-
您的 javascript 代码不完整。你错过了上面的东西吗?最后是右括号,会产生错误。
-
我没有添加我所有的 javascript 代码,因为其余的只是无关的 firebase 东西
-
我不需要 firebase 的东西。问题是,您的代码运行良好(当然,如果我删除了最后一个括号)。因此,如果没有更多代码,我实际上无法为您提供帮助。我的猜测是,你的 angular.module 没有被调用。
-
哦,好的,我会编辑我的帖子,并为您提供完整的 javascript。
-
还是 js 新手,但我的语法现在还好吗?我的 Angular js 仍然出现同样的错误,但没有语法错误
标签: jquery angularjs firebase firebase-realtime-database firebase-authentication