<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AngularJS CRUD</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.11/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular-route.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="myApp">
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo">CRUD</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="sass.html">Add</a></li>
<li><a href="badges.html">Admin</a></li>
</ul>
</div>
</nav>
<div class="row">
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s6">
<input placeholder="Placeholder" id="first_name" type="text" class="validate">
<label for="first_name">First Name</label>
</div>
<div class="input-field col s6">
<input id="last_name" type="text" class="validate">
<label for="last_name">Last Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input disabled value="I am not editable" id="disabled" type="text" class="validate">
<label for="disabled">Disabled</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="password" type="password" class="validate">
<label for="password">Password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="email" type="email" class="validate">
<label for="email">Email</label>
</div>
</div>
<div class="row">
<div class="col s12">
This is an inline input field:
<div class="input-field inline">
<input id="email_inline" type="email" class="validate">
<label for="email_inline">Email</label>
<span class="helper-text" data-error="wrong" data-success="right">Helper text</span>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
我的app.js
是:
var app = angular.module("myApp", []);
app.controller("addCtrl", function ($scope) {
$scope.products = ["Milk", "Bread", "Cheese"];
});
不知道为什么,但是出现错误:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.11/$injector/modulerr?p0=myApp&p1=Error%3A%20%5B%24injector%3Amoduler...
没有什么特别的。
答案 0 :(得分:1)
在您的JavaScript文件中,您定义了一个名为““ addCtrl”的控制器,但未将其包含在HTML中。
尝试在body标签中使用ng-controller =“ addCtrl”。