久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

angular.js - angular TypeError: Cannot read property ’id’ of undefined?

瀏覽:110日期:2024-09-28 11:53:53

問題描述

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é)生姓名angular.js - angular TypeError: Cannot read property ’id’ of undefined?3.控制臺(tái)報(bào)錯(cuò):

angular.js - angular TypeError: Cannot read property ’id’ of undefined?

angular.js - angular TypeError: Cannot read property ’id’ of undefined?

這是什么原因?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)文章:
主站蜘蛛池模板: 扎兰屯市| 湘阴县| 鹤庆县| 万盛区| 台中县| 柳州市| 徐州市| 普定县| 综艺| 荣成市| 项城市| 康乐县| 乾安县| 磐安县| 珠海市| 康乐县| 遂平县| 河源市| 灯塔市| 阜新| 香格里拉县| 仙桃市| 琼结县| 富顺县| 阳新县| 盘锦市| 姚安县| 瓦房店市| 永和县| 四平市| 灵石县| 白水县| 嘉兴市| 大英县| 南安市| 莱州市| 西昌市| 寿阳县| 桦甸市| 大邑县| 平泉县|