Answer the question
In order to leave comments, you need to log in
How to access an object in an angular directive?
Good day to all.
The topic of the question is a little clumsy .. But I will try to state the essence of the issue.
There is an application in angular. And there is a cloudinary service with their widget cloudinary.com/documentation/upload_widget
For cloudinary there is an angular wrapper from cloudinary themselves - but it is not complete .. for example, there is no widget there. etc.
Therefore, I decided to do it myself ... from the installation description to the widget
1) add a file to the page
<script src=" http://widget.cloudinary.com/global/all.js" type="text/javascript"></script>
cloudinary.openUploadWidget({ cloud_name: 'demo', upload_preset: 'a5vxnzbp'},
function(error, result) { console.log(error, result) });
}, false);
<script src=" http://widget.cloudinary.com/global/all.js" type="text/javascript"></script>
.directive(
'cloudinaryFileUpload', [function () {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (!angular.isDefined(ngModel)) {
return;
}
element.on(
'click', function () {
cloudinary.openUploadWidget(
{upload_preset: '******'},
function (error, result) {
console.log(error, result)
}
);
}
);
}
}
}]
)
cloudinary.openUploadWidget - is not a function
Answer the question
In order to leave comments, you need to log in
MNB Thanks for the reply... but that wasn't the problem... I forgot to disable the jquery cloudinary library. Which was used earlier .. and the cloudinary object is also given out there. And they interrupted each other .. And therefore, when I simply inserted a call to the widget on the page immediately after connecting the script with the widget, then it was called - and then there was an interruption to jquery and the wrong object was called in the directive.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question