gpt4 book ai didi

javascript - 错误 : [ng:areq] http://errors. angularjs.org/1.4.4/ng/areq?p0=FirstCtrl&p1=not%20a%20function%2C%20got%20undefined?

转载 作者:行者123 更新时间:2023-11-30 12:17:07 24 4
gpt4 key购买 nike

我是 angularjs 的新手,想知道我的代码有什么问题。我正在学习教程,但由于这个错误而卡住了。

索引.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS</title>
<link rel="stylesheet" href="foundation.min.css">
<script src="main.js"></script>
</head>
<body>

<div ng-app="">
<div ng-controller="FirstCtrl">

<h1>{{data.message + " world"}}</h1>
<div class="{{data.message}}">
Wrap me with foundation component
</div>
</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4
/angular.min.js"></script>
</body>
</html>

主要.js

function FirstCtrl($scope){
$scope.data = {message: "hello"};
}

最佳答案

您必须创建一个模块,如下所示:

var app = angular.module("MyApp",[]);
app.controller("FirstCtrl",function($scope){
$scope.data = {message: "hello"};
});



<div ng-app="MyApp">
<div ng-controller="FirstCtrl">

<h1>{{data.message + " world"}}</h1>
<div class="{{data.message}}">
Wrap me with foundation component
</div>
</div>
</div>

关于javascript - 错误 : [ng:areq] http://errors. angularjs.org/1.4.4/ng/areq?p0=FirstCtrl&p1=not%20a%20function%2C%20got%20undefined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32154376/

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