Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 链接范围中的属性是匿名函数_Javascript_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript 链接范围中的属性是匿名函数

Javascript 链接范围中的属性是匿名函数,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我编写自定义指令 在这段代码中,我希望从作用域中获取属性 return { restrict: 'A', scope: { user: '=', startDate: '=', daysInRow: '=' }, link: function (scope, element, attrs) { days = $rootScope.day

我编写自定义指令

在这段代码中,我希望从作用域中获取属性

return {
        restrict: 'A',
        scope: {
            user: '=',
            startDate: '=',
            daysInRow: '='
        },
        link: function (scope, element, attrs) {

            days = $rootScope.days[scope.user.id]; <-- here Id is undefined
我的问题是什么

用户对象:

admin:false
approver:false
defaultNotificationRecipient:false
defaultRecipient:false
defaultedNotifiers:null
defaultedRecepients:null
email:"sergiy.aleks@gmail.com"
endDate:Fri Feb 21 2014 14:00:00 GMT+0200 (FLE Standard Time)
id:4
initialValue:8
name:"Sergiy Aleks"
requestToUserCount:0
roles:Array[0]
startDate:Mon Sep 27 2010 15:00:00 GMT+0300 (FLE Daylight Time)
unAnsweredRequestToUserCount:0
userId:4
userRequestCount:0
vacationRate:0
console.log(scope.user)返回下一步:

function (a){return h(c,a)}

更新:正如我注意到的,这是由
ng repeat
track by$index
引起的。当我按user.id设置
跟踪时,我得到另一个错误:

中继器中不允许重复。使用“跟踪依据”表达式指定唯一关键点。Repeater:user in(filteredUsers=(用户| orderBy:'name'|筛选器:inSelectedGroups:user |筛选器:workTheseMonths))按user.id跟踪,重复键:未定义,重复值:{$$state:{“状态”:0}

但是
id
s应该是唯一的,所以我不知道这个错误

ng repeat
中,我使用
user
值传递给我的指令


更新2:

当我使用
track by$index
时,只有前4名用户返回
scope.user
作为函数,其他用户返回对象


更新3:

    <div class="row" ng-repeat="user in (filteredUsers = (users | orderBy:'name' | filter:inSelectedGroups:user | filter:workTheseMonths) ) track by user.id" ng-if="!user.visible">
                ...
                <div class="calendar-slider date-wrap" style="  margin-left: 15px;" ng-style="calendarOffset">
                    <div class="calendar-wrapper">
                        <div am-calendar-row user="user" start-date="calendar.startDay" days-in-row="calendar.numberDays"></div>
                    </div>
                </div>
            </div>

...

并证明,在
用户
集合中,我没有函数-

如果它是一个函数,则需要使用
&
而不是
=
@AlonEitan将其绑定到作用域,但
用户
是集合中的元素。我在
ng repeat
中使用collection
users
,效果很好。就为了这个指令,我得到了一个错误。顺便说一句,我试过
&
,但没有任何改变。用户的价值是什么?你能用你注入的用户对象所包含的内容更新吗?sas@KieranDotCo-当你执行
console.log(scope.user)时,你在指令中看到了什么?所以用户实际上是一个函数而不是一个对象。这个函数需要一个参数,你能描述一下这个参数是什么吗?
    <div class="row" ng-repeat="user in (filteredUsers = (users | orderBy:'name' | filter:inSelectedGroups:user | filter:workTheseMonths) ) track by user.id" ng-if="!user.visible">
                ...
                <div class="calendar-slider date-wrap" style="  margin-left: 15px;" ng-style="calendarOffset">
                    <div class="calendar-wrapper">
                        <div am-calendar-row user="user" start-date="calendar.startDay" days-in-row="calendar.numberDays"></div>
                    </div>
                </div>
            </div>