我想移动对象值以隔离指令中的范围但值未定义
<div>
<input ng-model="title" type='text'/>
<input ng-model="minDays" type='text'/>
<input ng-model="maxDays" type='text'/>
<week-days action="AddShift(week)" shiftPatterns = "shiftPatterns" style="display:inline-block"></week-days>
</div>
<div ng-repeat="shiftPattern in shiftPatterns">
<input type='text'ng-value="shiftPattern.title"></input>
<input type='text' ng-value="shiftPattern.minDays"></input>
<input type='text' ng-value="shiftPattern.maxDays"></input>
<week-days selectedDays="shiftPattern" style="display:inline-block"></week-days>
</div>
app.directive("weekDays", function(){
return{
restrict: "AEC",
scope: {
shiftPatterns: '=',
selectedDays: '=shiftPattern',
action: '&'
},
controller: function($scope, $element) {
$scope.week = [{"name":"MON", "selected":false} , {"name":"TUE", "selected":false} , {"name":"WED", "selected":false} , {"name":"THU", "selected":false} , {"name":"FRI", "selected":false} , {"name":"SAT", "selected":false} , {"name":"SUN", "selected":false} ];
$scope.AddOrRemoveDay = function(day){
day.selected = !day.selected
};
},
template: "{{selectedDays}}{{shiftPatterns}}<div style='width:500px; display:inline'>"+
"<div ng-repeat='day in week' ng-class=\"{true:'possibleDayStyle', false:'notPossibleDay'}[day.selected]\" ng-click='AddOrRemoveDay(day)'>"+
"{{day.name}}</div>"+
"</div>"+
"<button class='btnAddPossibleDays' ng-click='action({ week: week })'>Add</button>"
}
});
我想打印shiftPatterns和所选日期,但它未定义 https://jsfiddle.net/pudv35c0/5/
答案 0 :(得分:1)
要传递shiftPatterns的值,必须使用shift-patterns =“shiftPatterns”。可能还有其他问题,但我没有进一步讨论。对于selectedDays也是如此:selected-days =“...”