错误 .Uncaught SyntaxError:无效的简写属性initializer angular.js:38未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.5/ $ injector / modul
这是我的 app.js 代码:
var myApp = angular.module("myapp", ["ngRoute"]);
myApp.controller("myController", function($scope){
console.log("This is app.js ...........");
$scope.users = [
{username="John" , email="john@mail.com"},
{username="Adam" , email="Adam@adam.com"}
];
});
这是我的 index.html 代码:
<!DOCTYPE html>
<html lang="en-US">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myController">
<div class="container">
<button type="button" class="btn btn-primary pull-right"
data-toggle="modal" data-target="#myModal">Add Product</button>
<h2>Product List</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Index</th>
<th>UserName</th>
<th>Email</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{$index+1}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>
<button type="button" class="btn btn-warning" data-toggle="modal"
data-target="#myModalEdit">Edit</button>
</td>
<td>
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#myModalDelete">delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
答案 0 :(得分:4)
将ng-app="myApp"
修复为html文件中的ng-app="myapp"
。 check this plunkr
var myApp = angular.module("myApp", []);
myApp.controller("myController", function($scope){
console.log("This is app.js ...........");
$scope.users = [
{username: "John" , email:"john@mail.com"},
{username:"Adam" , email:"Adam@adam.com"}
];
});
答案 1 :(得分:1)
这不是声明对象的方式。替换= with:
$scope.users = [
{username:"Shanto" , email:"shanto@gmail.com"},
{username : "Adam" , email : "Adam@adam.com"}
];