由网友(土豪中的战斗豪!)分享简介:我有一个模式,我想用了两次,但不同的值。例如: .directive(天,函数($范围){ 返回{ 模板:'< DIV> {{天}}< / DIV>' } } 我可以用它在另两个指令,但封装天,看看结果这样的: < DIV> 1 L...
我有一个模式,我想用了两次,但不同的值。例如:
.directive(天,函数($范围){ 返回{ 模板:'< DIV> {{天}}< / DIV>' } }
我可以用它在另两个指令,但封装天,看看结果这样的:
< DIV> 1 LT; / DIV> < DIV> 2'; / DIV>
特别是,如果我希望将所有天
的绑定值解决方案你的意思是这样呢?
rr
app.directive('天',函数(){r 返回{r 范围: {r dayValue:'='r },r 模板:'< DIV> {{dayValue}}< / DIV>'r }r})rrapp.directive('outerDirective',函数(){r 返回{r 链接:功能($范围){r $ scope.days = [1,2,3];r },r 模板:'<日复一日值=天NG重复=日日>< /天>'r }r})
rrr
I have a pattern, which I want to use twice, but with different values. For example:
.directive("day", function($scope){
return {
template: '<div>{{day}}</div>'
}
}
Can I use it in two another directive, but encapsulate 'day' to see result like that:
<div>1</div>
<div>2</div>
Especially if I want to keep binding value of all 'day'
解决方案you meant something like this?
app.directive('day', function(){
return {
scope: {
dayValue: '='
},
template: '<div>{{dayValue}}</div>'
}
})
app.directive('outerDirective', function(){
return {
link: function($scope){
$scope.days = [1,2,3];
},
template: '<day day-value="day" ng-repeat="day in days"></day>'
}
})
相关推荐
最新文章