在angularjs ng-repeat

时间:2016-08-10 21:35:43

标签: html css angularjs

这是我想在angularjs中重新创建的有序列表, 忽略步骤从0开始的事实,稍后将更改为其他内容。

proper

它的来源在这里,数字由css反增量生成

HTML

    <ul id="progressbar">
        <li class="active">Step 0</li>
        <li>Step 1</li>
        <li>Step 2</li>
        <li>Step 3</li>         
    </ul>

CSS

/*custom font*/
@import url(http://fonts.googleapis.com/css?family=Montserrat);

/*basic reset*/
* {margin: 0; padding: 0;}

html {
	height: 100%;
	/*Image only BG fallback*/
	background: url('gs.png');
	/*background = gradient + image pattern combo*/
	background: 
		linear-gradient(rgba(196, 102, 0, 0.2), rgba(155, 89, 182, 0.2)), 
		url('gs.png');
}

body {
	font-family: montserrat, arial, verdana;
	background-color: transparent !important;
}
/*form styles*/
#msform {
	width: 480px;
	margin: 50px auto;
	text-align: center;
	position: relative;
}
#msform fieldset {
	background: white;
	border: 0 none;
	border-radius: 3px;
	box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
	padding: 20px 30px;
	
	box-sizing: border-box;
	width: 80%;
	margin: 0 10%;
	
	/*stacking fieldsets above each other*/
	position: absolute;
}
/*Hide all except first fieldset*/
#msform fieldset:not(:first-of-type) {
	display: none;
}
/*inputs*/
#msform input, #msform textarea {
	padding: 15px;
	border: 1px solid #ccc;
	border-radius: 3px;
	margin-bottom: 10px;
	width: 100%;
	box-sizing: border-box;
	font-family: montserrat;
	color: #2C3E50;
	font-size: 13px;
}
/*buttons*/
#msform .action-button {
	width: 100px;
	background: #27AE60;
	font-weight: bold;
	color: white;
	border: 0 none;
	border-radius: 1px;
	cursor: pointer;
	padding: 10px 5px;
	margin: 10px 5px;
}
#msform .action-button:hover, #msform .action-button:focus {
	box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60;
}
/*headings*/
.fs-title {
	font-size: 15px;
	text-transform: uppercase;
	color: #2C3E50;
	margin-bottom: 10px;
}
.fs-subtitle {
	font-weight: normal;
	font-size: 13px;
	color: #666;
	margin-bottom: 20px;
}
/*progressbar*/
#progressbar {
	margin-bottom: 30px;
	overflow: hidden;
	/*CSS counters to number the steps*/
	counter-reset: step;
}
#progressbar li {
	list-style-type: none;
	color: white;
	text-transform: uppercase;
	font-size: 9px;
	/* width should be 100 divided by the number of steps */
	width: 14.2857%;
	float: left;
	position: relative;
}
#progressbar li:before {
	content: counter(step);
	counter-increment: step;
	width: 20px;
	line-height: 20px;
	display: block;
	font-size: 10px;
	color: #333;
	background: white;
	border-radius: 3px;
	margin: 0 auto 5px auto;
}
/*progressbar connectors*/
#progressbar li:after {
	content: '';
	width: 100%;
	height: 2px;
	background: white;
	position: absolute;
	left: -50%;
	top: 9px;
	z-index: -1; /*put it behind the numbers*/
}
#progressbar li:first-child:after {
	/*connector not needed before the first step*/
	content: none; 
}
/*marking active/completed steps green*/
/*The number of the step and the connector before it = green*/
#progressbar li.active:before,  #progressbar li.active:after{
	background: #27AE60;
	color: white;
}

.rbContainer{ 
	white-space:nowrap;
	text-align: center;
}
.rbContainerN{ 
	white-space:nowrap;
	text-align: center;
	margin-left: -50px;
}

.rbContainerL{ 
	white-space:nowrap;
	float: left;
}
.rbContainerR{ 
	white-space:nowrap;
	float: right;
}
.lblY { float:left;  }
.inY { float:left;  }
<html>

<head>
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="http://kendo.cdn.telerik.com/2016.2.714/js/angular.min.js"></script>
  <script>
    angular.module("swiz", []).controller("bCtrl", function($scope) {
      $scope.fieldsets = [
        "Q 1",
        "Q 2",
        "Q 3",
        "Q 4"
      ];
    });
  </script>
</head>

<body ng-app='swiz' ng-controller="bCtrl">
  <ul id="progressbar">

    <div ng-repeat="fieldset in fieldsets">

      <li class="active" ng-if="$first">{{fieldset}}</li>

      <li ng-if="!$first">{{fieldset}}</li>
    </div>
  </ul>
</body>

</html>

*更新:是的,ng-repeat标记上的ul。但它也需要在divul(我有点生疏)

连接仍未显示

3 个答案:

答案 0 :(得分:5)

您需要将ng-repeat放在<li>而不是<ul>上。样式很混乱,因为它每次都会创建一个新的<ul>

<ul id="progressbar">
  <li class="active" ng-repeat="fieldset in fieldsets" >
    {{fieldset}}
  </li> 
</ul>

<强>更新

您仍然可以将ng-repeat放在<li>内。只需使用ng-class更改课程而不是ng-if

<ul id="progressbar">
    <li ng-class="{active: $first}" ng-repeat="fieldset in fieldsets">
      {{fieldset}}
    </li>
</ul>

<强> JSFiddle

答案 1 :(得分:1)

正如亨特所说,你要重复的元素是<li>,而不是<ul>,所以你应该ng-repeat放置<li>

另外,请尝试使用ng-class,而不是使用类<li>声明两个不同的.active,而不使用另一个.active。只有满足条件时才会添加课程<ul id="progressbar"> <li ng-class="{'active': $index == $first }" ng-repeat="fieldset in fieldsets" > step {{$index}} </li> </ul>

In [40]: pd.DataFrame(np.sort(df.values, axis=1), columns=df.columns).drop_duplicates()
Out[40]:
                source               target
0  1:19374802:19380807    2:4608900:4614600
1    2:4608900:4614600  5:14175176:14182011
3    2:4608900:4614600  5:14171600:14173742

答案 2 :(得分:1)

此外,请将此行用于active class

<li ng-class="$index==0 ? 'active' : ''" ></li>

<li ng-class="$first? 'active' : ''" ></li>