我是新的在angularjs,我想创建一个指令,以改变人类可读的文本。Angularjs指令替换文本
范围包括来自数据库的记录。我想改变它们匹配humanReadable数组。
angular.module('app', [])
.directive("humanReadable", function() {
return {
restrict: "A",
replace: true
}
});
var humanReadable= [{
text: "first_name",
replace: "First Name"
},
{
text: "last_name",
replace: "Last Name"
}];
function MyCtrl($scope) {
$scope.comesFromDatabase = ["first_name", "last_name"];
}
我的html是这样的。
<div ng-app="app">
<div ng-controller="MyCtrl">
<ul>
<li ng-repeat="item in comesFromDatabase">{{item}} -
<span human-readable="item"></span>
</li>
</ul>
</div>
</div>