我无法在我的纺纱元素上使用ng-show来工作。对于指令,我有一个孤立的范围,但由于它是我内部的一个元素,我认为它应该有用吗?
任何人都知道我做错了什么?
代码段:
angular.module('lr.upload.directives').directive('uploadButton', [
'upload',
function(upload) {
return {
restrict: 'EA',
scope: {
data: '=?data',
url: '@',
param: '@',
method: '@',
onUpload: '&',
onSuccess: '&',
onUploadTest: '&',
onError: '&',
onComplete: '&'
},
link: function(scope, element, attr) {
scope.uploading=false;
var el = angular.element(element);
var fileInput = angular.element('<input type="file" />');
var spinningElement = angular.element('<img ng-show="uploading" class="uploadSpinner" src="../../img/loading.gif" />');
el.append(fileInput);
el.append(spinningElement);
解决方案:
angular.module('lr.upload.directives').directive('uploadButton', [
'upload', '$compile',
function(upload, $compile) {
return {
restrict: 'EA',
scope: {
data: '=?data',
url: '@',
param: '@',
method: '@',
onUpload: '&',
onSuccess: '&',
onUploadTest: '&',
onError: '&',
onComplete: '&'
},
link: function(scope, element, attr) {
scope.uploading = false;
var el = angular.element(element);
var fileInput = angular.element('<input type="file" />');
var spinningElement = $compile('<img ng-show="uploading" class="uploadSpinner" src="../../img/loading.gif" />')(scope);
el.append(fileInput);
el.append(spinningElement);
答案 0 :(得分:1)
我认为您应该使用$ compile来使其正常工作
var spinningElement = $compile('<img ng-show="uploading" class="uploadSpinner"
src="../../img/loading.gif" />')(scope);