作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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/
我是一名优秀的程序员,十分优秀!