angular.js - angular TypeError: Cannot read property ’id’ of undefined?
問題描述
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://m.baoyu77737.com/bower_components/angular/angular.min.js'></script> <script type='text/javascript' src='http://m.baoyu77737.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://m.baoyu77737.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.先打開5-7.html2.點(diǎn)擊學(xué)生姓名3.控制臺(tái)報(bào)錯(cuò):
這是什么原因?qū)е碌模瑫?huì)是這句的問題嗎?href='http://m.baoyu77737.com/wenda/14218.html#view/:id'
問題解答
回答1:a5_7.controller(’c5_7_2’,[’$scope’, function($scope,$routeParams){//沒有注入$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 - 如何修改運(yùn)行中容器的配置3. python3.x - python連oanda的模擬交易api獲取json問題第五問4. node.js - 我是一個(gè)做前端的,求教如何學(xué)習(xí)vue,node等js引擎?5. java - SSH框架中寫分頁(yè)時(shí)service層中不能注入分頁(yè)類6. angular.js - angular內(nèi)容過長(zhǎng)展開收起效果7. 為什么我ping不通我的docker容器呢???8. docker-machine添加一個(gè)已有的docker主機(jī)問題9. javascript - js代碼獲取驗(yàn)證碼倒計(jì)時(shí)問題10. 關(guān)于docker下的nginx壓力測(cè)試
