无法解决NG错误:不好的论点

时间:2017-07-20 14:33:05

标签: javascript angularjs

我收到一个角度误差,需要一些帮助! 链接到错误:https://docs.angularjs.org/error/ng/areq?p0=LoginCtrl&p1=not%20a

"Error: ng:areq
Bad Argument
Argument 'LoginCtrl' is not a"

我一直在研究这个问题已经有一段时间了,在这里找不到我做错了什么。我已经研究过这个错误并且我的脚本是正确的,我相信我的函数是正确的语法明智...我试图把ng-view取出来并把它放在另一个局部,这解决了我的错误问题但是打破了我的游戏。

的index.html:

<!DOCTYPE html>
    <html>
    <head>
      <title>Memory Game</title>
    <!-- <meta name="google-signin-client_id" content="344924208843-lr7f74mh6q2j9sn3kadb5i93m6ne6pnd.apps.googleusercontent.com"> -->
    </head>
    <link rel="stylesheet" href="lib/node_modules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">

    <link rel="stylesheet" type="text/css" href="styles/main.css">

    <div ng-include="'partials/navBar.html'"></div>

    <body ng-app="MemoryGame">

    <div class="ng-view">

    </div>

    <script type="text/javascript" src="lib/bower_components/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
    <script type="text/javascript" src="lib/node_modules/angular/angular.min.js"></script>
    <script type="text/javascript" src= "lib/node_modules/angularfire/dist/angularfire.min.js"></script>
    <script type="text/javascript" src="lib/node_modules/angular-route/angular-route.min.js"></script>



    <!-- My Stuff -->
    <script type="text/javascript" src="app/app.js"></script>
    <script type="text/javascript" src="app/factories/authFactory.js"></script>
    <script type="text/javascript" src="app/factories/gameFactory.js"></script>
    <script type="text/javascript" src="app/controllers/LoginCtrl.js"></script>
    <script type="text/javascript" src="app/controllers/ProfileCtrl.js"></script>
    <script type="text/javascript" src="app/controllers/DashboardCtrl.js"></script>

    </body>
    </html>

LoginCtrl.js

'use strict'

app.controller("LoginCtrl", function($scope, $rootScope,$location, $window,firebaseURL, authFactory) {

  let ref = new Firebase(firebaseURL);

  if($location.path() === "/login") {
    ref.unauth()
  };

$scope.login = () => {
    authFactory
      .Googlelogin($scope.account)
      .then(function(stuff) {
        $window.location.assign('/#/profile');
      })
    };
});

app.js

'use strict'

var app = angular.module("MemoryGame", ["ngRoute"])
  .constant("firebaseURL", "https://memapp.firebaseio.com/");

let isAuth = (authFactory) => new Promise((resolve, reject) => {
  if(authFactory.isAuthenticated()) {
    console.log("User is authenticated, resolve route promise");
    resolve();
  } else {
    console.log("User is not authenticated, reject route promise");
    reject();
  }
});


app.config(function($routeProvider) {
  $routeProvider.
  when('/', {
    templateUrl:'partials/userProfile.html',
    controller: "ProfileCtrl"
    // resolve: {isAuth},
  }).
  when('/login',{
    templateUrl:'partials/login.html',
    controller:"LoginCtrl"
  }).
  when('/profile',{
    templateUrl:'partials/userProfile.html',
    controller:"ProfileCtrl",
    resolve: {isAuth},
  }).
  when('/dashboard',{
    templateUrl:'partials/dashboard.html',
    controller:"DashboardCtrl",
    resolve: {isAuth}
  }).
  otherwise('/')
});

profileCtrl.js

'use strict'
app.controller("ProfileCtrl", function($scope, $rootScope, $location,$timeout,firebaseURL, gameStorage){

let matches = [];
let moves = 0;
let score = 0;

//an array of objects for cards
$scope.cards = [
  {id :"card1",isFlipped:false, emojPics:"../data/Emoji-Poop.png", value:0},
  {id: "card2",isFlipped: false, emojPics:"../data/Emoji-facePlant.png", value:1},
  {id: "card3",isFlipped:false, emojPics: "../data/Emoji-Whatever.jpeg", value:2},
  {id :"card1",isFlipped:false, emojPics:"../data/Emoji-Poop.png", value:3},
  {id: "card2",isFlipped: false, emojPics:"../data/Emoji-facePlant.png", value:4},
  {id: "card3",isFlipped:false, emojPics: "../data/Emoji-Whatever.jpeg", value:5}
];

//setting display/username to root scope
$rootScope.loggedInUserDisplayName = "";
console.log("rootScope validated");

//checks for number of cards clicked
function checkRound(card) {
  moves += 1
  console.log("number of moves ",moves)
  if (moves <= 2){
    isFlipped(card);
    console.log("does this trigger a 2nd time? ");
  }
  else if(moves > 2) {
    console.log("More than 2 Moves");
  }
};

AuthFactory.js

app.factory("authFactory", function(firebaseURL,$rootScope) {
  let ref = new Firebase(firebaseURL);
  let currentUserData = null;
  let isNewUser = true;

  return {

  Determine if the client is authenticated through firebase

    isAuthenticated () {
      let authData = ref.getAuth();
      //if statement if user is authenticated or not
      return (authData) ? true : false;
    },

    getUser () {
      return currentUserData;
    },


//Authenticate the client via Firebase

    Googlelogin(){
      return new Promise((resolve, reject) => {
        ref.authWithOAuthPopup("google", function(error, authData) {
          console.log("auth error", error);
          if (error) {
          console.log("Login Failed!", error);
          reject();
          }else{
          console.log("Authenticated successfully with payload:",
           authData);
          $rootScope.username = authData.google.displayName;
          resolve(authData);
          }
        })
      })
    },

  Store each Firebase user's id in the `users` collection

    storeUser (authData) {
      let stringifiedUser = JSON.stringify({ uid: authData.uid });

      return new Promise((resolve, reject) => {
        $http
          .post(`${firebaseURL}/users.json`, stringifiedUser)
          .then(
            res => resolve(res),
            err => reject(err)
          );
      });
    }
  };
});

gameFactory.js

'use strict'
app.factory("gameStorage", function($q, $http, firebaseURL, authFactory){

var getGameList = function(){
        let games = [];
        let ref = new Firebase(firebaseURL);
        let authData = ref.getAuth();
        let user = authFactory.getUser();
    return $q(function(resolve, reject){
      $http.get(`${firebaseURL}games.json?orderBy="uid"&equalTo= "${authData.uid}"`)
        .success(function(gameObject){
          var gameCollection = gameObject;
          Object.keys(gameCollection).forEach(function(key){
            gameCollection[key].id=key;
            games.push(gameCollection[key]);
            console.log("gameCollection",gameCollection);
              });
            resolve(games);
              })
            .error(function(error){
            reject(error);
        });
    });
  };
//
//   var getSingleGame = function(gameId) {
//     console.log("gameId",gameId);
//     return $q(function(resolve, reject){
//       $http.get( firebaseURL + "games/"+gameId+".json")
//         .success(function(gameObject){
//           resolve(gameObject);
//         })
//         .error(function(error){
//           reject(error);
//         });
//     });
//   }
//
//  var deleteGame = function(gameId){
//     return $q(function(resolve, reject){
//       $http
//         .delete( firebaseURL + `games/${gameId}.json`)
//         .success(function(objectFromFirebase){
//             resolve(objectFromFirebase);
//         });
//     });
//   };
//
//     var postNewGame = function(newGame){
//         // let user = authFactory.authData.displayName
//         // console.log("user",user);
//         let ref = new Firebase(firebaseURL);
//         let authData = ref.getAuth();
//         // console.log("authData",authData);
//         console.log("uid", authData.uid);
//             return $q(function(resolve, reject) {
//                 $http.post(
//                 firebaseURL + "games.json",
//                 JSON.stringify({
//                     uid: authData.uid,
//                     timeLeft: newGame.timeLeft,
//                     matches: newGame.matches
//                     })
//                 )
//             .success(
//                 function(objectFromFirebase) {
//                     resolve(objectFromFirebase);
//                 });
//         });
//     };
//
//
return{postNewGame:postNewGame,getGameList:getGameList,deleteGame:deleteGame,getSingleGame:getSingleGame};

});

2 个答案:

答案 0 :(得分:0)

如果ProfileCtrl位于文件profileCtrl.js中且小写“p”。由于<script>index.html引用的区分大小写,可能无法加载文件。

变化:

<script type="text/javascript" src="app/controllers/ProfileCtrl.js"></script>

为:

<script type="text/javascript" src="app/controllers/profileCtrl.js"></script>

或者尝试将文件名从profileCtrl.js更改为ProfileCtrl.js以匹配<script>参考。

<强>更新

关于您的其他error,我认为与AuthFactory.js中的index.html文件引用相同的区分大小写问题。该文件未加载,这就是Unknown Provider错误的原因。正在发生

变化:

<script type="text/javascript" src="app/factories/authFactory.js"></script>

要:

<script type="text/javascript" src="app/factories/AuthFactory.js"></script>

希望这有帮助!

答案 1 :(得分:0)

我认为这里存在问题:

<div ng-include="'partials/navBar.html'"></div>

<body ng-app="MemoryGame">

您在ng-app包含之外包含角度代码。

我建议将ng-app =“MemoryGame”附加到html标签或将ng-include添加到正文中。无论如何都应该是html中的情况。

希望这有帮助。