为什么我的AngularJS代码不起作用?

时间:2016-08-30 07:24:13

标签: javascript angularjs

请帮我修复这个脚本:

var newsFeed = angular.module('newsFeed', []);

var newsFeedModule = angular.module('newsFeed');

newsFeedModule.controller('newsFeedController', function($scope) {
    $scope.posterWidth = 100;
    $scope.posterHeight = 60;

});

HTML:

<div ng-app="newsFeed">
  <div ng-controller="newsFeedController">
    {{ 2+3 }}
    {{ posterWidth }}
  </div>
</div>

我制作了一个简单的AngularJS脚本,它将显示如上所述的变量和表达式。但是没有计算出这些值。我试过几次,你可以看到下面的JSFiddle。

JSFIDDLE

3 个答案:

答案 0 :(得分:2)

JSFiddle中,您需要点击 JAVASCRIPT 按钮,然后在angular 1.4.8下拉列表中选择Frameworks & Extensions,然后选择No wrap in head选项在Load type下拉列表....现在它将起作用

enter image description here

JSFIDDLE

答案 1 :(得分:0)

工作示例

https://jsfiddle.net/yeLm5j8u/3/

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

<div ng-app="newsFeed">
  <div ng-controller="newsFeedController">
    {{ 2+3 }}
    {{ posterWidth }}
  </div>
</div>

</body>
<script>
var newsFeed = angular.module('newsFeed', []);

var newsFeedModule = angular.module('newsFeed');

newsFeedModule.controller('newsFeedController', function($scope) {
    $scope.posterWidth = 100;
    $scope.posterHeight = 60;


});
</script>
</html>

答案 2 :(得分:-1)

需要包含AngularJS!