Javascript 将ng init替换为范围变量不会';行不通
在下面的angularjs代码中,我尝试使用scope而不是ng init,但没有任何解释为什么Javascript 将ng init替换为范围变量不会';行不通,javascript,angularjs,Javascript,Angularjs,在下面的angularjs代码中,我尝试使用scope而不是ng init,但没有任何解释为什么 <!doctype html> <html ng-app="myApp" ng-controller="myCtrl"> <head> <title>Bookshop - Your Online Bookshop</title> <meta charset="UTF-8"> <
<!doctype html>
<html ng-app="myApp" ng-controller="myCtrl">
<head>
<title>Bookshop - Your Online Bookshop</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
</head>
<body>
<div class="container">
<h2>Your Online Bookshop</h2>
<ul class="unstyled">
<li ng-repeat="book in books">
{{book}}
</li>
</ul>
</div>
<div class="container">
<h2>Your Online Bookshop</h2>
<ul class="unstyled">
<li ng-repeat="book in books_author">
<span>{{book.name}} written by {{book.author}}</span>
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.books = ['Effective Java','Year without Pants','Confessions of public speaker','JavaScript Good Parts'];
$scope.books_author = [{'name': 'Effective Java', 'author':'Joshua Bloch'},{'name': 'Year without Pants', 'author':'Scott Berkun'},{ 'name':'Confessions of public speaker','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas Crockford'}];
});
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
</body>
</html>
书店-你的网上书店
你的网上书店
-
{{book}}
你的网上书店
-
{{book.name}}由{{book.author}编写
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.books=['Effective Java'、'Year not Pants'、'commissions of public speaker'、'JavaScript Good Parts'];
$scope.books_author=[{'name':'Effective Java','author':'Joshua Bloch'},{'name':'Year without tants','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas crokford'},{';
});
它对我有效,但在使用它之前必须加载角度。因此,请改为:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.books = ['Effective Java','Year without Pants','Confessions of public speaker','JavaScript Good Parts'];
$scope.books_author = [{'name': 'Effective Java', 'author':'Joshua Bloch'},{'name': 'Year without Pants', 'author':'Scott Berkun'},{ 'name':'Confessions of public speaker','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas Crockford'}];
});
</script>
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.books=['Effective Java'、'Year not Pants'、'commissions of public speaker'、'JavaScript Good Parts'];
$scope.books_author=[{'name':'Effective Java','author':'Joshua Bloch'},{'name':'Year without tants','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas crokford'},{';
});
它对我有效,但在使用它之前必须加载角度。因此,请改为:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.books = ['Effective Java','Year without Pants','Confessions of public speaker','JavaScript Good Parts'];
$scope.books_author = [{'name': 'Effective Java', 'author':'Joshua Bloch'},{'name': 'Year without Pants', 'author':'Scott Berkun'},{ 'name':'Confessions of public speaker','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas Crockford'}];
});
</script>
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.books=['Effective Java'、'Year not Pants'、'commissions of public speaker'、'JavaScript Good Parts'];
$scope.books_author=[{'name':'Effective Java','author':'Joshua Bloch'},{'name':'Year without tants','author':'Scott Berkun'},{'name':'JavaScript Good Parts','author':'Douglas crokford'},{';
});
代码很好,只要在包含AngularJS时移动行即可:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
在自定义脚本中使用它之前,它将起作用 代码很好,只要在包含AngularJS时移动行即可:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
在自定义脚本中使用它之前,它将起作用