gpt4 book ai didi

javascript - 错误 : [ng:areq] Argument is not a function, 未定义

转载 作者:行者123 更新时间:2023-12-03 09:10:23 25 4
gpt4 key购买 nike

我试图用 Angular 制作一个简单的应用程序,我偶然发现了

enter image description here

页面加载时弹出错误。我做错了什么?

views/raffle/index.html.erb

<h1>Raffler</h1>

<div ng-controller="RaffleCtrl">
<form>
<input type="text" ng-model="newEntry.name">
</form>

<ul>
<li ng-repeat="entry in entries">
{{entry.name}}
</li>
</ul>
</div>

assets/javascript/raffle.js.coffee

@RaffleCtrl = ($scope) ->
$scope.entries = [
{name: "Larry"}
{name: "Curly"}
{name: "Moe"}
]

views/layouts/application.html.erb

<!DOCTYPE html>
<html ng-app>
<head>
<title>AngularTestProject</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>

<body>
<div id="container">
<%= yield %>
</div>
</body>

</html>

最佳答案

你可以做到,

<div ng-app="myApp">
<h1>Raffler</h1>

<div ng-controller="RaffleCtrl">
<form>
<input type="text" ng-model="newEntry.name">
</form>
<ul>
<li ng-repeat="entry in entries">{{entry.name}}</li>
</ul>
</div>
</div>

angular.module('myApp', []).controller("RaffleCtrl", function ($scope) {
$scope.entries = [{
name: "Larry"
}, {
name: "Curly"
}, {
name: "Moe"
}];

});

DEMO

关于javascript - 错误 : [ng:areq] Argument is not a function, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32089332/

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