![](/img/trans.png)
[英]TypeError: Cannot read property 'name' of undefined in angularJS
[英]ERROR TypeError: Cannot read property 'name' of undefined - Using angularjs
我正在嘗試讓ng-repeat重復主題列表,但出現此錯誤。
錯誤
> TableUsersComponent.html:23 ERROR TypeError: Cannot read property
> 'name' of undefined
> at Object.eval [as updateRenderer] (TableUsersComponent.html:23)
> at Object.debugUpdateRenderer [as updateRenderer] (core.js:11080)
> at checkAndUpdateView (core.js:10456)
> at callViewAction (core.js:10692)
> at execComponentViewsAction (core.js:10634)
> at checkAndUpdateView (core.js:10457)
> at callViewAction (core.js:10692)
> at execComponentViewsAction (core.js:10634)
> at checkAndUpdateView (core.js:10457)
> at callWithDebugContext (core.js:11344)
HTML代碼
<div ng-app="DemoApp" ng-controller="DemoController" class="ng-scope ng-binding">
<h1>Topics</h1>
<ul><li ng-repeat="tpname in TopicNames track by $index">
{{tpname.name}}
</li></ul>
</div>
JS代碼
var app = angular.module('DemoApp',[]);
app.controller('DemoController', function($scope){
$scope.model = {};
$scope.TopicNames =[
{name: "What controller do from Angular's perspective"},
{name: "Controller Methods"},
{name: "Building a basic controller"}];
});
我已經在代碼段中嘗試過您的代碼,並且工作正常。 通過與您的代碼段和本代碼段代碼進行比較,請在找不到任何內容的地方找到它。
var app = angular.module('DemoApp',[]); app.controller('DemoController', function($scope){ $scope.model = {}; $scope.TopicNames =[ {name: "What controller do from Angular's perspective"}, {name: "Controller Methods"}, {name: "Building a basic controller"}]; });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <div ng-app="DemoApp" ng-controller="DemoController" class="ng-scope ng-binding"> <h1>Topics</h1> <ul><li ng-repeat="tpname in TopicNames track by $index"> {{tpname.name}} </li></ul> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.