2016-02-10 26 views
-1

你能告訴我這段代碼有什麼問題。當我使用$ scope的時候它工作正常,但是當我用下面的代碼替換它時不會。這個角度js代碼有什麼問題(我正在使用這個代替範圍在控制器中)

<!DOCTYPE html> 
<html> 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<body> 

<div ng-app="myApp" ng-controller="myCtrl as person"> 

`<h1>{{person.name}}</h1> 

</div> 

<script> 
var app = angular.module('myApp', []); 
app.controller('myCtrl', function() { 
    var student = {name:"Volvo", 
        age: 20}; 
    this.student = student; 



}); 
</script> 

<p>The property "carname" was made in the controller, and can be referred to in the view by using the {{ }} brackets.</p> 

</body> 
</html> 

回答

0

這裏的人是myCtrl別名。

蘇使用像,person.student.name

0

試試這個:

<h1>{{person.student.name}}</h1> 
0

我沒有看到你所定義的範圍,也沒有提及拉的數據,無論是從你的模型或某種API的拉直。你錯過了在這裏展示的東西嗎?