我正在构建一个 MEAN-STACK 应用程序(这对我来说是新的)并从这个模板开始:https ://github.com/linnovate/mean
我想添加一个模块(称为 cloudinary),所以我遵循了这个: http ://cloudinary.com/documentation/node_image_upload#direct_uploading_environment_setup
(npm install、bower 等......完成)
我被困在这条线上(不知道该怎么做):
cloudinary.uploader.image_upload_tag('image_id', { callback: cloudinary_cors });
在我的应用程序中有一个控制器和一个服务。如果我把它放在控制器中,我会收到消息“cloudinary is undifined”。也许我应该把它放在服务文件中,但我不知道怎么做。我在我的 html 页面中创建了一个表单,其中包含一个输入,该输入应该从我的控制器上传一个调用“cloudyPost()”函数的文件。
这是我的控制器、服务和页面的代码:
mycars.js(服务):
//Cars service used for car REST endpoint
angular.module('mean.mycars').factory('Cars', ['$resource', function($resource) {
return $resource('cars/:carId', {
carId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}]);
mycars.js(控制器):
angular.module('mean.mycars').controller('MyCarsController', ['$scope', '$http', '$stateParams', '$location', 'Global', 'Cars',
function ($scope, $http, $stateParams, $location, Global, Cars) {
$scope.cloudPost = function() {
cloudinary.uploader.image_upload_tag('image_id', { callback: cloudinary_cors });
};
[.... some other code ....]
}
我的html页面:
<section data-ng-controller="MyCarsController" data-ng-init="findOneOrCreate()">
<form role="form" data-ng-submit="cloudyPost()">
<p>Public ID: <input type="text" name="title"/></p>
<p>Image: <input type="file" name="image"/></p>
<p><button type="submit" class="btn btn-default">Send to Cloudy!</button> </p>
</form>
</section>
你能帮我把所有这些整合在一起并让它工作吗?谢谢你。
这里添加的是我页面最后包含的js):
<script type="text/javascript" src="/lib/angular/angular.js"></script>
<script type="text/javascript" src="/lib/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="/lib/angular-resource/angular-resource.js"></script>
<script type="text/javascript" src="/lib/angular-ui-router/release/angular-ui-router.js"></script>
<script type="text/javascript" src="/lib/angular-bootstrap/ui-bootstrap.js"></script>
<script type="text/javascript" src="/lib/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="/lib/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/lib/ng-grid/build/ng-grid.js"></script>
<script type="text/javascript" src="/lib/cloudinary/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/lib/cloudinary/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="/lib/cloudinary/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="/lib/cloudinary/js/jquery.cloudinary.js"></script>
<script type="text/javascript" src="/js/app.js"></script>
<script type="text/javascript" src="/js/config.js"></script>
<script type="text/javascript" src="/js/controllers/articles.js"></script>
<script type="text/javascript" src="/js/controllers/car.js"></script>
<script type="text/javascript" src="/js/controllers/header.js"></script>
<script type="text/javascript" src="/js/controllers/index.js"></script>
<script type="text/javascript" src="/js/controllers/mycars.js"></script>
<script type="text/javascript" src="/js/directives.js"></script>
<script type="text/javascript" src="/js/filters.js"></script>
<script type="text/javascript" src="/js/init.js"></script>
<script type="text/javascript" src="/js/services/articles.js"></script>
<script type="text/javascript" src="/js/services/cars.js"></script>
<script type="text/javascript" src="/js/services/global.js"></script>
<script type="text/javascript" src="/js/services/mycars.js"></script>
<!-- Livereload script rendered -->
<script type="text/javascript" src="http://localhost:35729/livereload.js"></script>