2015-11-11 72 views
2

我開始使用AngularJS在我網站的成員部分工作。Angular JS錯誤:未檢測到模塊

v0.1.0.php

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title><?php echo ucfirst($_SERVER['PHP_AUTH_USER']); ?>'s dashboard</title> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script> 
     <script src="../jquery-2.1.4.min.js"></script> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
     <script src="app.js" type="text/javascript"></script> 
    </head> 
    <body ng-app="usr" ng-controller="userControll as users" ng-init=<?php echo "'users.setUser(" . $_SERVER['PHP_AUTH_USER'] .")'"?>><!-- since I'm using server auth, to transfer to angular--> 
     <div style="background-color: #000000; color: #c0c0c0;"> 
       <div class="container"> 
        <img ng-src="{{users.user.icon}}" alt="avatar" /> 
        <h1>{{users.user.name}}</h1> 
        <i>@<?php echo $_SERVER['PHP_AUTH_USER']; ?></i> 
       </div> 
     </div> 
     <div class="container"> 
       <h1>Dashboard</h1> 
       <!--Nav tabs--> 
       <ul class="nav nav-tabs" role="tablist"> 
        <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li> 
        <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li> 
        <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li> 
       </ul> 
       <div class="tab-content"> 
        <div role="tabpanel" class="tab-pane fade in active" id="home"><h1>Home</h1><br>{{users.user.data}}</div> 
        <div role="tabpanel" class="tab-pane fade" id="profile"> 
          <h2>{{users.user.name}}</h2> 
          <hr> 
          <span style="color: gray">Coming soon</span> 
        </div> 
        <div role="tabpanel" class="tab-pane fade" id="settings"> 
          <h2>Settings</h2> 
          <span style="color: gray">Coming soon</span> 
          <hr> 
          <h3>About</h3> 
          <i>v0.1.0<br>&copy; Imagifight Studios 2015</i> 
        </div> 
       </div> 
     </div> 
    </body> 
</html> 

app.js

(function(){ 
    var app = angular.module('usr', []); 
    var userData = $.ajax({ 
     dataType: 'json', 
     url:'user-data.json' 
    }) 
    .done(function(data) { 
     $.each(function(data){ 
       $.parseJSON(data); 
     }); 
    }).fail(console.error('Damn. Didn\'t work.')); 

    app.controller('userControll', function(){ 
     this.setUser = function(u){ 
       this.user = userData[u]; 
     } 
    }) 
})(); 

用戶data.json

{ 
    "imagifight": { 
     "name": "Imagifight", 
     "email": "[email protected]", 
     "status": "owner", 
     "icon": "icons/imagifight.png" 
    } 
} 

拋出錯誤:

Damn.Didnt work
(anonymous function) @ app.js:11

無法看到ajax出錯的地方。沒有語法錯誤。也許我在這裏錯過了一些東西,我不知道。任何想法如何解決?

+0

失敗給出了一個錯誤味精或代碼..告訴Ÿ失敗AJAX ..嘗試'.fail(執行console.log);'或'.fail( console.error);' – Minato

+0

看看這個[fiddle](https://jsfiddle.net/yL6gh1fq/) – Minato

+0

看看這個[fiddle](http://jsfiddle.net/zkqw9qqx/3/) 。在你試圖達到的目標中存在一些問題..雖然我已經通過一些骯髒的黑客來完成它,但是你可以從代碼 – Minato

回答

0

報價問題。將其轉義爲

console.error('Damn. Didn\'t work.') 
0

您有'控制檯內部錯誤。

變化:console.error('Damn. Didn't work.')

爲:console.error('Damn. Didn\'t work.')

+0

對不起。我忘了在這裏逃避它。我是在我的代碼中完成的。 – Imagifight