angular报错

本文探讨了在Angular应用中遇到的面包屑导航报错问题。通过分析`breadcrumb.html`文件的代码,重点关注`ng-repeat`、`ng-class`和`ng-if`指令的使用,解释了错误产生的原因,并提供了相应的解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>封装一个面包屑导航</title>
<!-- 引入angular的库 -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<script src="bower_components/angular/angular.js"></script>


</head>
<!-- ng-app用来声明 angular  执行的边界 
ng-controller 用来声明 我们要调用哪一个 controller
-->
<body ng-app="myAppDemo" ng-controller="myAppController">
<!-- 这是我们自定义的指令 -->
<breadcrumb data='{{pathData}}'></breadcrumb>
<script>
//声明我们的模块  myApp
let myApp = angular.module('myAppDemo', []);
/*在模块写创建一个控制器 myAppController*/
myApp.controller('myAppController', ['$scope', function($scope){
/*定义一个数组*/
$scope.pathData = {
first:'#',
second:'#',
third:'#',
fourth:'#',
};
}]);


//定义一个面包屑导航指令
myApp.directive('breadcrumb', [function(){
/*返回指令对象*/
return{
scope:{},
templateUrl:'temps/breadcrumb.html',
replace:true,
link:function(scope, element, attributes){
scope.data = JSON.parse(attributes.data);
console.log(scope.data);
}
};
}]);
</script>
</body>

</html>



/**

breadcrumb.html文件

*/

<ol class="breadcrumb">
<li ng-repeat="(key, value) in data track by $index">
<a href="{{value}}" ng-class="{{active:$last}}" 
ng-if="!$last">{{key}}</a>
<span ng-if="$last"></span>
</li>
</ol>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值