【发布时间】:2014-05-19 20:07:09
【问题描述】:
我需要设置 ID,我只使用模板和链接。 ID看起来像
id="number1"
id="number2"
id="number3"
...
id="number' + (index++)'"'
但未生成 ID。这不是循环。
如果我使用 $compile MyApp 不起作用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script>
var index=0; //Iterator
angular.module('app', [])
.directive('tttt', function(){
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
value: '@'
},
template: '<input type="text" id="number' + (index++) + '" ></input>',
link: function(scope, element, attrs) {
scope.value = attrs.value;
}
};
});
</script>
<body>
<div ng-app="app">
<tttt value="http://google.com">google</tttt>
<tttt value="http://mail.ru">mail</tttt>
</div>
</body>
</html>
谢谢。
【问题讨论】:
标签: javascript html angularjs angularjs-directive