新角度。也许我很密集,但不确定是否有其他人看到我遇到的同样的问题,尽管我检查了规定的命名错误。我使用常规Ctrl作为控制器的简写。
我的聊天控制器ChatCtrl.js
如下
angular.module("blocChat")
.controller("ChatCtrl", function($scope, Message, Room) {
$scope.roomName
$scope.rooms = Room.all
$scope.goToRoom = function(room) {
$scope.selectedRoom = room
console.log($scope.selectedRoom)
$scope.messages = Message.getByRoomId($scope.selectedRoom.id)
}
$scope.message = function() {
}
});
我的Index.html
如下:
<!DOCTYPE html>
<html ng-app="blocChat">
<head lang="en">
<meta charset="UTF-8">
<title>Bloc Chat Project</title>
<link rel="stylesheet" href="/styles/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,600,700,300">
<link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link rel="stylesheet" type="text/css" href="styles/normalize.css">
<!-- <link rel="stylesheet" href="/styles/landing.css"> -->
<link rel="stylesheet" href="/styles/home.css">
<link rel="stylesheet" href="/styles/room.css">
<link rel="stylesheet" type="text/css" href="/styles/style.css" />
</head>
<body class="home" ng-controller="ChatCtrl">
<!-- <ng-include src="'/templates/home.html'"></ng-include> -->
<h1>Bloc Chat</h1>
<h2>{{ roomName }}</h2>
<ul><li ng-repeat="room in rooms"><a ng-click="goToRoom(room)">{{ room.name }}</a></li></ul>
<h1>Room: {{ selectedRoom.name }}<h1>
<h2>Room Html<h2>
<div><li ng-repeat="message in messages"> {{ message.text }} </li></div>
<script data-require="angular.js@1.6.1" data-semver="1.6.1" src="https://code.angularjs.org/1.6.1/angular.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- ui's -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-animate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<!-- firebase -->
<script src="https://www.gstatic.com/firebasejs/3.6.6/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>
<!-- css -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css"></script> -->
<!-- app scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-cookies.js"></script>
<script src="/scripts/app.js"></script>
<script src="/scripts/controllers/ChatCtrl.js"></script>
<script src="/scripts/controllers/HomeCtrl.js"></script>
<script src="/scripts/controllers/RoomCtrl.js"></script>
<script src="/scripts/controllers/UsernameCtrl.js"></script>
<script src="/scripts/factory/Message.js"></script>
<script src="/scripts/factory/Room.js"></script>
</body>
</html>
这发生在我创建以下文件的时候,但我被告知这可能只是巧合,UsernameCtrl.js
:
angular.module("blocChat", ['ui.bootstrap'])
.controller("UsernameCtrl", function($scope, $uibModal) {
$uibModal.open({
controller: "ModalCtrl",
templateUrl: "/templates/username.html"
})
})
.controller("ModalCtrl", function($uibModalInstance, $scope) {
$scope.user = {
username: "John",
password: "test"
}
})
.run(function($uibModal) {
$uibModal.open({
controller: "ModalCtrl",
templateUrl: "/templates/username.html"
})
})
app.js
中的代码:
angular
.module('blocChat', ['firebase', 'ui.bootstrap'])
.config(function($locationProvider) {
var config = {
apiKey: // Firebase API key
authDomain:// Firebase Auth domain ("*.firebaseapp.com")
databaseURL: // Firebase Database URL("https://*.firebaseio.com")
storageBucket: "bloc-chat-117d5.appspot.com",
messagingSenderId: "324260113714"
};
firebase.initializeApp(config);
})
我的整体代码在这里:https://github.com/seanbode/bloc-chat
当我致电[]
时,我在ChatCtrl.js
中使用angular.module("blocChat")
时已经尝试过它。我很感激您可以给我的任何建议,因为我知道我在编码方面有很多东西需要学习。谢谢。
答案 0 :(得分:2)
您要声明两次相同的模块
没有第二个参数anguler.module('moduleName')
是一个吸气剂。但是使用依赖注入参数它是一个setter。
变化:
angular.module("blocChat", [])
要
angular.module("blocChat")
或者将依赖注入移动到此声明,因为脚本加载的顺序首先加载