var myApp = angular.module('myApp', [])
.directive("unorderedList", function () {
return function(scope, element, attrs) {
};
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS Demo</title>
<link rel="stylesheet" href="../css/bootstrap.css" rel="external nofollow" />
<link rel="stylesheet" href="../css/bootstrap-theme.css" rel="external nofollow" >
<script src="../js/angular.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Products</h3>
</div>
<div class="panel-body">
<div unordered-list="products"></div>
</div>
</div>
</body>
<script>
var myApp = angular.module('myApp', [])
.controller('myCtrl', ["$scope", function ($scope) {
$scope.products = [
{ name: "Apples", category: "Fruit", price: 1.20, expiry: 10 },
{ name: "Bananas", category: "Fruit", price: 2.42, expiry: 7 },
{ name: "Pears", category: "Fruit", price: 2.02, expiry: 6 }
];
}])
.directive("unorderedList", function () {
return function (scope, element, attrs) {
var data = scope[attrs['unorderedList']];
if( angular.isArray(data) ){
for(var i=0, len=data.length; i<len; i++){
console.log(data[i].name);
}
}
};
});
</script>
</html>
<div unordered-list="products" list-property="name"></div>
var data = scope[attrs['unorderedList']];
var propertyName = attrs['listProperty'];
if(angular.isArray(data)){
var listElem = angular.element("<ul>");
element.append(listElem);
for(var i=0, len=data.length; i<len; i++){
listElem.append( angular.element('<li>').text(data[i][propertyName]) );
}
}
<div unordered-list="products" list-property="price | currency"></div>
listElem.append( angular.element('<li>').text(scope.$eval(propertyName, data[i])) );
<div class="panel-body">
<button class="btn btn-primary" ng-click="incrementPrices()">
Change Prices
</button>
</div>
$scope.incrementPrices = function () {
for(var i=0,len = $scope.products.length; i<len; i++){
$scope.products[i].price++;
}
}
if(angular.isArray(data)){
var listElem = angular.element("<ul>");
element.append(listElem);
for(var i=0, len=data.length; i<len; i++){
var itemElem = angular.element('<li>');
listElem.append(itemElem);
var watchFn = function (watchScope) {
return watchScope.$eval(propertyName, data[i]);
};
scope.$watch(watchFn, function (newValue, oldValue) {
itemElem.text(newValue);
});
}
}
for(var i=0, len=data.length; i<len; i++){
(function () {
var itemElem = angular.element('<li>');
listElem.append(itemElem);
var index = i;
var watchFn = function (watchScope) {
return watchScope.$eval(propertyName, data[index]);
};
scope.$watch(watchFn, function (newValue, oldValue) {
itemElem.text(newValue);
});
}());
}
(function (i) {
var itemElem = angular.element('<li>');
listElem.append(itemElem);
var watchFn = function (watchScope) {
return watchScope.$eval(propertyName, data[i]);
};
scope.$watch(watchFn, function (newValue, oldValue) {
itemElem.text(newValue);
});
})(i);
return function (scope, element, attrs) {
var listElem = element.append("<ol>");
for (var i = 0; i < scope.names.length; i++) {
listElem.append("<li>").append("<span>").text(scope.names[i]);
}
}
return function (scope, element, attrs) {
var listElem = angular.element("<ol>");
element.append(listElem);
for (var i = 0; i < scope.names.length; i++) {
listElem.append(angular.element("<li>")
.append(angular.element("<span>").text(scope.names[i])));
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有