我创建了一个带有名称和扩展属性的erray,我想用ng-repeat遍历它。 我可以知道我在这里做错了什么吗?
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en" ng-app="">
<head>
<script src="js/angular.min.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome to angular js</title>
</head>
<body>
<div ng-init="myFavLanguage=[{name:'PHP', extension:'.php'},{name='JAVA', extnsion='.java'}]">
<p ng-repeat="lang in myFavLanguage">
Name: {{lang.name}}<br>
Extension: {{lang.extension}}<br>
</p>
</div>
</body>
</html>
答案 0 :(得分:1)
您错误地在对象中分配值(在'JAVA'部分中):
<div ng-init="myFavLanguage=[{name:'PHP', extension:'.php'},{name='JAVA', extnsion='.java'}]">
将此更改为:
<div ng-init="myFavLanguage=[{name: 'PHP', extension: '.php'}, {name: 'JAVA', extnsion: '.java'}]">