gpt4 book ai didi

javascript - 简单的 Angular 示例不起作用

转载 作者:行者123 更新时间:2023-11-28 11:33:40 25 4
gpt4 key购买 nike

我已经复制了 an angular example from w3schools (here) ,而且它不起作用。我不明白为什么。看起来应该工作正常。我做错了什么?

Here's a plunker of my experiment

这是 Angular JS:

angular.module('myApp', []).controller('thingsCtrl', function($scope) {
$scope.things = [
{title: 'my title 1', content: 'my Content 1'},
title: 'my title 2', content: 'my Content 2'},
title: 'my title 3', content: 'my Content 3'},
title: 'my title 4', content: 'my Content 4'},
title: 'my title 5', content: 'my Content 5'},
title: 'my title 6', content: 'my Content 6'}
];

$scope.things2 = [
{title: 'my 2nd title 1', content: 'my Content 1'},
title: 'my 2nd title 2', content: 'my Content 2'},
title: 'my 2nd title 3', content: 'my Content 3'},
title: 'my 2nd title 4', content: 'my Content 4'},
title: 'my 2nd title 5', content: 'my Content 5'},
title: 'my 2nd title 6', content: 'my Content 6'}
];
});

这是 HTML:

    <!DOCTYPE html>
<html>

<head>

<!-- CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">

<!-- JS -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

</head>

<body>

<div ng-app="myApp" ng-controller="thingsCtrl">
<h1>Hello Plunker!</h1>



<div class="container">
<div class="row">

<div class="col-sx-6"><h4>My Subtitle</h4>
<div ng-repeat="x in things">
<div class="col-sx-6 col-sm-4 col-md-2">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}

</div>
</div>
</div>
</div>

<div class="col-sx-6"><h4>My Subtitle</h4>
<div ng-repeat="x in things2">
<div class="col-sx-6 col-sm-4 col-md-2">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}

</div>
</div>
</div>
</div>

</div>
</div>

</div>

<script src="script.js"></script>

</body>

</html>

最佳答案

您在标记中指定了错误的 Controller 。更新

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

<div ng-app="myApp" ng-controller="thingsCtrl">

关于javascript - 简单的 Angular 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31415341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com