我是angularjs的初学者
我有前端代码
<html>
<head>
<title>Scope Data</title>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="aplikasi.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="BukuController">
<div>
<ul>
<li ng-repeat="b in bukus">
<p>Judul : {{b.judul }}</p>
</li>
</ul>
</div>
</div>
</body>
</html>
和js
var myApp=angular.module("myApp",[]);
function BukuController($scope){
$scope.bukus={
"java":{
"kode":"java",
"judul":"Java EE Programming",
"penulis":"Rahman dkk"
},
"javascript":{
"kode":"javascript",
"judul":"Javascript 2014",
"penulis":"Rully"
},
"net":{
"kode":"net",
"judul":"Advanced .Net platform",
"penulis":"Rloio"
},
"php":{
"kode":"php",
"judul":"Php legacy code",
"penulis":"Ruzman"
}
}
$scope.selectedBuku=null;
$scope.setBuku=function(code){
$scope.selectedBuku=$scope.bukus[code];
}
}
但是如果我在浏览器上运行index.html,它会显示空白并看到错误
错误:[ng:areq] http://errors.angularjs.org/1.3.15/ng/areq?p0=BukuController&p1=not%20a%20function%2C%20got%20undefined 在错误(本机) 在file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:6:417 在Rb(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:19:510) at sb(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:20:78) at $ get(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:75:396) 在file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:57:100 at r(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:7:408) 在B(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:56:471) at g(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:51:335) at g(file:/// D:/training/di%20luar%20lussa/belajar/app/angular.min.js:51:352)(匿名) 函数)@ angular.min.js:102 $ get @ angular.min.js:76 $ get.n. $ apply @ angular.min.js:126(匿名函数)@ angular.min.js:17e @ angular.min.js:36d @ angular.min.js:17uc @ angular.min.js:18Jd @ angular.min.js:17(匿名函数)@ angular.min.js:250a @ angular.min.js:164c @ angular.min.js:32
我的问题是什么?请帮我 在此之前,谢谢,
答案 0 :(得分:1)
fordg,您的代码似乎按原样运行(无修改,无控制台错误):https://jsfiddle.net/b4ox1Lnt/
它可能是.js文件的简单引用位置问题(在您的HTML script
标记中) - 您的HTML标记表明index.html和两个.js文件位于同一文件夹中,这是真的? (还要检查.js文件名是否正确)
GL!