Angularjs angularfire使用$loaded如何访问指令中的数据

Angularjs angularfire使用$loaded如何访问指令中的数据,angularjs,firebase,angularfire,Angularjs,Firebase,Angularfire,这篇文章是对 目标是将img设置为visibily并设置src html 但是我有 [异常…对包装原型对象nsresult的非法操作:0x8057000c NS\u错误\u XPC\u错误\u OP\u在\u WN\u PROTO上 我真的不明白为什么 console.log(scope.item);// Object { $$conf={...}, $id="-J_C-q-6bIW9PBZzqpAg" console.log(angular.equals({}, scope.item));//

这篇文章是对 目标是将img设置为visibily并设置src

html

但是我有 [异常…对包装原型对象nsresult的非法操作:0x8057000c NS\u错误\u XPC\u错误\u OP\u在\u WN\u PROTO上

我真的不明白为什么

console.log(scope.item);// Object { $$conf={...}, $id="-J_C-q-6bIW9PBZzqpAg"
console.log(angular.equals({}, scope.item));// but this is true !
丑陋的结局

如果任何人有更好的解决方案,欢迎:
}

那么这里的问题是什么呢?只选一个怎么样?angularfire$loaded可以访问指令中的值是一条语句,可能有5个内联问题和一段稍微相关的代码。这是否可以缩小到仅一个问题和一段代码,以确切地说明该问题?为什么我的代码不能工作是e基本上要求我调试我的代码;看。那么你的观点是什么?你想更改标题吗?或者,在我的结束时进行“丑陋的黑客”双美元加载是正常的。有没有办法在指令中获得值?我遵循了所有的So规则,所以我没有真正看到要点,顺便说一句,我更改了标题。
app.controller('ItemsUpdateController', function ($scope, item, Items, $state) {
    item.$loaded().then(function(data) {
        $scope.item = data;   
    });
    $scope.add = function() {console.log($scope.item);
       /* Items.update(item.$id,$scope.item).then(function () {
            $state.transitionTo('items');
        });*/
    }
});
app.directive('uploader', function() {
    return {
        restrict: 'A',
        scope:{
            item: '='
        },
        link: function(scope, element, attrs) {
            if (window.File && window.FileReader && window.FileList && window.Blob) {
                var fileElem = angular.element('<input type="file" style="display:none;">');
                var imgElem = angular.element('<img src="" width="50" style="margin-left:10px;visibility:hidden;">');
                element.after(fileElem);
                element.after(imgElem);console.log(scope.item); //This give me undefined
                /*if(scope.item.url){
                     imgElem.css('visibility','visible');
                     imgElem[0].src = scope.item.url;
                }*/
                fileElem.on('change',function(e){
                    e.stopPropagation();
                    var files = e.target.files;
                    var reader  = new FileReader();
                    reader.onloadend = function () {
                        var url = reader.result;
                        imgElem.css('visibility','visible');
                        imgElem[0].src = url;
                        scope.$apply(function () {
                           scope.item.url = url;
                        });
                    }
                    reader.readAsDataURL(files[0]);
                });
                element.on('click', function(e) {
                    e.stopPropagation();
                    fileElem[0].click();
                });
                element.on('$destroy',function(){
                    element.off('click');
                });
                fileElem.on('$destroy',function(){
                    fileElem.off('change');
                });

            }
        },
    };
});
scope.$watch('item', function(newVal, oldVal){
     console.log(newVal, oldVal);
}, true);
console.log(scope.item);// Object { $$conf={...}, $id="-J_C-q-6bIW9PBZzqpAg"
console.log(angular.equals({}, scope.item));// but this is true !
//controller
$scope.item = item;
$scope.item.$loaded().then(function(data) {
  $scope.item = data;   
});
//directive
if(scope.item.$id){
    scope.item.$loaded().then(function(data) {
        imgElem.css('visibility','visible');
        imgElem[0].src = data.url;
    });