Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的AngularJS代码不起作用?_Javascript_Angularjs - Fatal编程技术网

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

Javascript 为什么我的AngularJS代码不起作用?,javascript,angularjs,Javascript,Angularjs,请帮助我修复此脚本: var newsFeed = angular.module('newsFeed', []); var newsFeedModule = angular.module('newsFeed'); newsFeedModule.controller('newsFeedController', function($scope) { $scope.posterWidth = 100; $scope.posterHeight = 60; }); html: {

请帮助我修复此脚本:

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

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

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

});
html:


{{ 2+3 }}
{{posterWidth}}
我制作了一个简单的AngularJS脚本,它将如上所示显示变量和表达式。但是这些数值并没有被计算出来。我已经试过几次了,您可以看到下面的JSFiddle


你需要加入AngularJS

工作示例


{{ 2+3 }}
{{posterWidth}}
var newsFeed=angular.module('newsFeed',[]);
var newsFeedModule=angular.module('newsFeed');
newsFeedModule.controller('newsFeedController',函数($scope){
$scope.posterWidth=100;
$scope.posterHeight=60;
});

JSFiddle
中,您需要单击JAVASCRIPT按钮,并需要在
框架和扩展
下拉列表中选择
angular 1.4.8
,然后在
加载类型
下拉列表中选择
无缠绕头部
选项。。。。现在它可以工作了


我认为没有适当的方法来参考模块初始化。您应该将此引用
newsfeedmodel
和init controller删除到
newsFeed
模块。它会工作的,是的,你应该在
DOM
上加载angularjs。但是angularjs已经加载了。请参阅上的“外部资源”jsfiddle@sergey.sergeyd2016,用fiddle更新了我的ans。包括angularjs。请参阅jsfiddle上的“外部资源”为什么需要newsFeedModule?你已经有新闻提要了。newsFeed.controler('newsFeedController')。。。
<div ng-app="newsFeed">
  <div ng-controller="newsFeedController">
    {{ 2+3 }}
    {{ posterWidth }}
  </div>
</div>
<!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>