2016-08-27 16 views
-1

Angular JSを学び始めています。名前、年齢、職業を表示する次のコードを書きました。私はAngular 1.5を使用しています。単純なJS/JSONがAngularで動作しない

<!-- View --> 
 

 
<div ng-controller="MyController"> 
 
    <h1> {{author.name}} </h1> 
 
    <p>{{author.age + " " + author.profession}}</p> 
 
</div> 
 

 

 
<!-- MODAL --> 
 
<script> 
 
    function MyController($scope) { 
 
    $scope.author = { 
 
     'name': 'Muhammad', 
 
     'age': '35', 
 
     'profession': 'Software Engineer' 
 
    } 
 
    } 
 
</script>

任意の助けもいただければ幸いです。

var app = angular.module("main", []); 
app.controller("MyController", MyController); 

<html ng-app="main"> 
<div ng-controller="MyController"> 
    <h1> {{author.name}} </h1> 
    <p>{{author.age + " " + author.profession}}</p> 
</div> 

</html> 

作業例:あなたは、モジュールを追加する必要が

+0

ます( "[あなたのモジュール]")angular.moduleする関数 'MyController'を渡したのコントローラ( "MyController"、' MyController').. –

答えて

0

あなたが不足している何があなたのHTMLの角度モジュールとNG-アプリディレクティブです。

この無料コースに簡単に従ってください。 https://www.codeschool.com/courses/shaping-up-with-angular-js

簡単なサンプルコード:

<html ng-app="myApp"> 
<div ng-controller="MyController"> 
    <h1> {{author.name}} </h1> 
    <p>{{author.age + " " + author.profession}}</p> 
</div> 

<script src="angular.min.js"></script> 

<script> 
    angular.module('myApp', []) 
     .controller('MyController', function ($scope) { 
      $scope.author = { 
       'name': 'Muhammad', 
       'age': '35', 
       'profession': 'Software Engineer' 
      } 
     }); 
</script> 

<html> 
関連する問題