angular.js - 请教angular中scope作用域的问题
伊谢尔伦
伊谢尔伦 2017-05-15 16:58:56
0
1
466
AppendBookApp.controller('MainController', ['$rootScope', function($rootScope) {
    
    $rootScope.image = {};
    $rootScope.image.exists = true;
    $rootScope.image.src = '';

    $rootScope.uploader = WebUploader.create({
        server: '/upload/test',
        swf: '/libs/WebUploader/Uploader.swf',
        chunked: true,
        disableGlobalDnd: true,
        dnd: document.body,
        paste: document.body,
        pick: {
            id: '#UploadImageButton',
            label: '点击选择图片'
        },
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        },
        compress: false,
        auto: true
    });

    // setTimeout(function() {
    //     $rootScope.image.src = '';
    //     console.log($rootScope.image.src);
    // }, 2000);
    //     $rootScope.image.src = '/uploadfile/2c12c2170d0a2eaee8c061060f9f91f1.png';

    $rootScope.uploader.onUploadSuccess = function(file, res) {
        $rootScope.image.src = res._raw;
        $rootScope.image.exists = true;
        console.log($rootScope.image.src);
    };

    $('.webuploader-pick').removeClass('webuploader-pick').addClass('btn btn-primary');

}]);

为什么我在上传成功的回调函数里修改scope,界面没反应

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

membalas semua(1)
伊谢尔伦

Malah, data telah berjaya diubah suai Antara muka tidak bertindak balas kerana ringkasan tidak dicetuskan. Hanya tukar kod kepada yang berikut

$rootScope.uploader.onUploadSuccess = function(file, res) {
    $rootScope.$apply(function () {
        $rootScope.image.src = res._raw;
        $rootScope.image.exists = true;
        console.log($rootScope.image.src);
    });
};
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan