我正在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>
Run Code Online (Sandbox Code Playgroud)
片段A(教授证明我无法上班):
var app = angular.module('confusionApp',[]);
app.controller('dishDetailController', function() {
var dish={ //attributes here; };
this.dish = dish;
});
Run Code Online (Sandbox Code Playgroud)
当我运行此功能时,我在控制台中没有出现任何错误,但我在显示屏上没有任何内容.
代码片段B:
var app = angular.module('confusionApp',[]);
app.controller('dishDetailController', function($scope) {
var dish={ //attributes here;};
$scope.dish = dish;
});
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它的工作原理.有区别吗?