我正在Coursera上学习AngularJS课程。
讲师在视频中展示的代码可以运行,但出于某些原因,我不能在我的环境中运行:
页面布局(部分):
<div class="media-body">
<h2 class="media-heading">{{dish.name}}
<span class="label label-danger">{{dish.label}}</span>
<span class="badge">{{dish.price | currency}}</span></h2>
<p>{{dish.description}}</p>
</div>
Snippet A(由我无法工作的教授演示):
代码段A:
var app = angular.module('confusionApp',[]);
app.controller('dishDetailController', function() {
var dish={ //attributes here; };
this.dish = dish;
});
当我运行这个函数时,控制台没有任何错误提示,但是在显示屏上也没有任何内容。
代码段B:
var app = angular.module('confusionApp',[]);
app.controller('dishDetailController', function($scope) {
var dish={ //attributes here;};
$scope.dish = dish;
});
当我这样做时,它有效。有什么区别吗?
$scope.<etc>
。 - miltonb