angular.js - angular TypeError: Cannot read property ’id’ of undefined?
問(wèn)題描述
demo功能描述:在一個(gè)頁(yè)面中實(shí)現(xiàn)學(xué)生信息瀏覽的功能。首先,以列表的方式顯示全部學(xué)生的姓名;然后,當(dāng)在列表單擊某個(gè)學(xué)生姓名時(shí),進(jìn)入改學(xué)生的詳細(xì)資料頁(yè)。顯示該學(xué)生的全部資料。5-7.html
<!DOCTYPE html><html lang='en' ng-app='a5_7'><head> <meta charset='UTF-8'> <title>Title</title> <script type='text/javascript' src='http://www.b3g6.com/bower_components/angular/angular.min.js'></script> <script type='text/javascript' src='http://www.b3g6.com/bower_components/angular-route/angular-route.min.js'></script> <style>body{ font-size:13px;}.show{ background-color:#cccccc; padding:8px; width:260px; margin:10px 0;} </style></head><body> <h1>瀏覽學(xué)生信息的主頁(yè)</h1><p ng-view></p></body><script type='text/javascript'>var a5_7 = angular.module(’a5_7’,[’ngRoute’]); a5_7.controller(’c5_7_1’,[’$scope’, function($scope){$scope.students = students; }]); a5_7.controller(’c5_7_2’,[’$scope’, function($scope,$routeParams){for(var i=0; i<students.length; i++){// console.log(students.student[i]); if(students[i].stuId == $routeParams.id){$scope.student = students[i];break; }} }]); a5_7.config([’$routeProvider’, function($routeProvider){$routeProvider.when(’/’,{ controller:’c5_7_1’, templateUrl:’5-7-1.html’}).when(’/view/:id’,{ controller:’c5_7_2’, templateUrl:’5-7-2.html’, publicAccess:true}).otherwise({ redirectTo:’/’}); }]); var students = [{ stuId:1000, name:’張明明’,sex:’女’,score:60},{ stuId:1001, name:’李清思’,sex:’女’,score:80},{ stuId:1002, name:’劉小華’,sex:’男’,score:90},{ stuId:1003, name:’陳總總’,sex:’男’,score:70} ]</script></html>
5-7-1.html
<p ng-repeat='stu in students' class='show'> <a href='http://www.b3g6.com/wenda/14218.html#view/:id'>{{stu.name}}</a></p>
5-7-2.html
<p class='show'> <p>學(xué)號(hào):{{student.stuId}}</p> <p>姓名:{{student.name}}</p> <p>性別:{{student.sex}}</p> <p>分?jǐn)?shù):{{student.score}}</p></p>
操作步驟:1.先打開(kāi)5-7.html2.點(diǎn)擊學(xué)生姓名
3.控制臺(tái)報(bào)錯(cuò):


這是什么原因?qū)е碌模瑫?huì)是這句的問(wèn)題嗎?href='http://www.b3g6.com/wenda/14218.html#view/:id'
問(wèn)題解答
回答1:a5_7.controller(’c5_7_2’,[’$scope’, function($scope,$routeParams){//沒(méi)有注入$routeParams
請(qǐng)更改為
a5_7.controller(’c5_7_2’,[’$scope’,’$routeParams’, function($scope,$routeParams){
相關(guān)文章:
1. nignx - docker內(nèi)nginx 80端口被占用2. docker容器呢SSH為什么連不通呢?3. javascript - 連續(xù)點(diǎn)擊觸發(fā)mouseleave事件4. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?5. 關(guān)于docker下的nginx壓力測(cè)試6. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””7. mac里的docker如何命令行開(kāi)啟呢?8. docker gitlab 如何git clone?9. dockerfile - 我用docker build的時(shí)候出現(xiàn)下邊問(wèn)題 麻煩幫我看一下10. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。

網(wǎng)公網(wǎng)安備