2016-07-17 9 views
0

私は初心者のプログラマーであり、Music Storeアプリケーションと共に角度をつけて学習しています。私はangularJSにメッセージを表示する際にいくつかの問題を抱えていて、コード内の問題か、それとも何か他のものかどうか疑問に思っていました。私の期待される結果は単にページに "Manish Kumar"を表示することです。しかし、私の実際の結果は単にhtmlから{{message}}を表示しているだけです。それは、JSコントローラリファレンスを取得していないかのようです。私が2015年を使っている間、この例はVS 2013で行われたことに注意してください。私は初心者なのでどんな助けもありがとうございます。ありがとう!!AngularJSが正しくメッセージを表示しない

マイコード&ファイル:

インデックスHTML:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 

    <script src="../../Scripts/angular.js"></script> 
    <script src="../Scripts/theMusic.js"></script> 
    <script src="../Scripts/MusicListController.js"></script> 
</head> 
<body> 
    <div ng-app="theMusic"> 
     <div ng-controller="MusicListController"> 
      {{message}} 
     </div> 
    </div> 
</body> 
</html> 

MusicListController:

(function (app) { 
    var MusicListController = function ($scope) { 
     $scope.message = "Manish Kumar"; 
    }; 
    app.controller("MusicListController", MusicListController); 
}(Angular.module("theMusic"))); 

theMusicクラス:

(function() { 
    var app = Angular.module("theMusic", []); 
}()); 
+0

、あなたのブラウザのコンソール内の任意のjsエラーを持っていますか? – Shyju

+1

わかりませんが、角度を角度に変更します。 – developer033

+0

エラーを表示していません。 MusicListControllerをどのように参照しているのでしょうか?ありがとう! – AndrewC10

答えて

1

私はこのタイプを試してみてください。あなたの問題を解決して、ちょっとした変更を加えてください。

(function() { 
 
    var app = angular.module("theMusic", []); 
 
}()); 
 

 
(function (app) { 
 
    var MusicListController = function ($scope) { 
 
     $scope.message = "Manish Kumar"; 
 
    }; 
 
    app.controller("MusicListController", MusicListController); 
 
}(angular.module("theMusic")));
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script> 
 
<!DOCTYPE html> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
    <title></title> 
 

 
    <script src="../../Scripts/angular.js"></script> 
 
    <script src="../Scripts/theMusic.js"></script> 
 
    <script src="../Scripts/MusicListController.js"></script> 
 
</head> 
 
<body> 
 
    <div ng-app="theMusic"> 
 
     <div ng-controller="MusicListController"> 
 
      {{message}} 
 
     </div> 
 
    </div> 
 
</body> 
 
</html>

+0

ありがとう、ビジェイ。それはよさそうだ! – AndrewC10

関連する問題