Angular1.x入门级自定义组件(导航条)

简介: Angular1.x入门级自定义组件(导航条)

<!DOCTYPE html>

<html lang="zh" ng-app="app">

<head>

   <meta charset="UTF-8">

   <title>百度导航条</title>

   <script src="../angular.js"></script>

   <link rel="stylesheet" href="myComponent.css">

   <script src="myComponent.js"></script>

</head>

<body>

<my-component menu="网页|资讯|视频|图片|知道|文库|贴吧|采购|地图|更多»"></my-component>

</body>

</html>


var app = angular.module('app', []);

app.directive('myComponent', function () {

   return {

       templateUrl: 'myComponent.html',

       controller: 'controllerName',

   };

});

app.run(["$templateCache", function ($templateCache) {

   $templateCache.put("myComponent.html", "<div class='baidu-nav'><li ng-repeat='item in list'>{{item}}</li></div>");

}]);

 

app.controller('controllerName', function ($scope, $attrs) {

   $scope.list = $attrs.menu.split("|");

});


@charset "UTF-8";

/*这里设置组件的样式*/

 

.baidu-nav {

   width: 100%;

   background: #f8f8f8;

   line-height: 36px;

   height: 38px;

 

}

 

li {

   cursor: pointer;

   list-style: none;

   float: left;

   width: 54px;

   height: 38px;

   display: inline-block;

   text-decoration: none;

   text-align: center;

   color: #666;

   font-size: 14px;

}

 

li:hover, li.active {

   border-bottom: 2px solid #38f;

   font-weight: 700;

   color: #323232;

}

相关文章
|
23天前
|
JavaScript
Angular使用@Input和@Output实现父子组件互相传参(类似Vue的props和this.emit)
Angular使用@Input和@Output实现父子组件互相传参(类似Vue的props和this.emit)
|
4月前
|
前端开发 JavaScript
Angular 组件模版代码里使用 ngIf 进行条件渲染的例子
Angular 组件模版代码里使用 ngIf 进行条件渲染的例子
22 0
|
5月前
Angular多个页面引入同一个组件报错The Component ‘MyComponentComponent‘ is declared by more than one NgModule怎么办?
Angular多个页面引入同一个组件报错The Component ‘MyComponentComponent‘ is declared by more than one NgModule怎么办?
|
5月前
快速创建Angular组件并定义传参、绑定自定义事件的方法
快速创建Angular组件并定义传参、绑定自定义事件的方法
|
7月前
Angular HTTP 请求自定义 timeout 值的一种实现思路
Angular HTTP 请求自定义 timeout 值的一种实现思路
29 1
|
资源调度 JavaScript 容器
Angular封装WangEditor富文本组件
Angular封装WangEditor富文本组件
205 0
|
资源调度 前端开发 Java
使用Angular CDK实现一个Service弹出Toast组件
使用Angular CDK实现一个Service弹出Toast组件
88 0
|
JavaScript 前端开发 API
让Angular自定义组件支持form表单验证
让Angular自定义组件支持form表单验证
115 0
Angular组件传参
Input 是属性装饰器,用来定义组件内的输入属性。在实际应用场合,我们主要用来实现父组件向子组件传递数据。Angular 应用是由各式各样的组件组成,当应用启动时,Angular 会从根组件开始启动,并解析整棵组件树,数据由上而下流下下一级子组件。
|
资源调度
angular使用ngx-vant组件库
angular使用ngx-vant组件库

热门文章

最新文章