Tag: angularjs

$ scope。当我从指令更新时,$ watch不会触发

我有以下代码片段: HTML: <div data-filedrop data-ng-model="file"></div> 控制器: $scope.$watch('file', function(newVal) { if (newVal) { alert("File",newVal); }, false); } 指示: angular.module('app').directive('filedrop', function () { return { restrict: 'A', templateUrl: './directives/filedrop.html', replace: true, scope: { ngModel: '=ngModel' }, link: function (scope, element) { var dropzone = element[0]; dropzone.ondragover = function () { this.className = 'hover'; return false; }; dropzone.ondragend […]

Angular应用程序需要node.js

我将要创build我的第一个angular度应用程序。 我读过很多angular度教程,其中很多提到了node.js.我真的很困惑。 我们是否真的需要安装node.js和其他依赖来运行angular度应用程序? 我不能只在我的日食中添加相应的angular库,并创buildAngular应用程序? 使用node.js的优点是什么? 还有必要添加所有angular码在App文件夹下? 问候,Dip

在NodeJS上使用PouchDB进行文档附件

我有一个集成了PouchDB的AngularJS应用程序。 我想向PouchDB添加一个文档,但是从下面的文档中不太清楚: db.putAttachment(docId, attachmentId, rev, doc, type, [callback]); 将二进制对象附加到文档。 PouchDB的大部分API都处理JSON,但是如果你处理的是大的二进制数据(比如PNG),那么如果你简单地把它们包含为base64或者hex编码的string的话,你可能会遭受性能或者存储惩罚。 在这些情况下,您可以将二进制数据存储为附件。 有关详细信息,请参阅附件上的CouchDB文档。 用法示例: var doc = new Blob(["It's a God awful small affair"]); db.putAttachment('a', 'text', rev, doc, 'text/plain', function(err, res) {}) 在Node中,您必须使用缓冲区而不是Blob: var doc = new Buffer("It's a God awful small affair"); 在我的应用程序中,我已经达到了以下的地步: var file = document.getElementById('file'); 现在,我如何使用缓冲区来将我的文件添加到数据库? 另外,是否有可能自动生成一个有效的docID,attachementID和rev? 那么MS Office文档的types是什么? 谢谢!

节点js HTTPServer / StaticServlet POST请求

我对Node js比较陌生。 我已经build立了基于angular-requirejs-seed的 Node js / Angular Application 但是,我发现脚本/ web-server.js混淆,因为我曾经用express来开发节点js服务器。 特别是,我想实现file upload,但至less,我想知道我如何可以在脚本/ web-server.js中实现POST请求处理程序 function main(argv) { new HttpServer({ 'GET': createServlet(StaticServlet), 'HEAD': createServlet(StaticServlet) }).start(Number(argv[2]) || DEFAULT_PORT); } 请指导我正确的方向。

使用node和angularjs为configuration文件设置自动化

我几周前在AngularJS开始了一个应用程序。 我所有的configurationvariables都存储在像这样的常量: /** * defines constants for application */ define(['angular'], function (ng) { 'use strict'; return ng.module('app.constants', []) .constant('CONFIG', { node_port: 3700, api_host: 'api.acme.local', node_host: 'acme.com', facebook_app_id: 'xxxxxxxxx' }); }); 我遇到的问题是每次我想在舞台上推送我的应用程序时,我需要更改此值。 我正在使用rsync所以我可以忽略这个文件,并在舞台服务器上修改一次。 这可能不是最好的解决scheme,但它会工作。 现在我最近使用express和socket.io添加了一个nodejs服务器到我的应用程序,这意味着我现在必须在我的angularjs应用程序和server.js设置客户端。 因为我正在使用requirejs我还需要更新socket.io的path。 requirejs: paths: { 'jquery': 'bower_components/jquery/dist/jquery.min', … 'socketio': 'http://acme.local:3700/socket.io/socket.io' }, 和我的server.js : var express = require('express'), debug = true, http = […]

哟angular度错误

我正在尝试通过命令来通过Yeoman构buildAngular “哟angular” 一切工作,直到我到了tmp目录: npm ERR! Error: EACCES, mkdir '/home/colin/tmp/npm-10021-myBKjnB0' npm ERR! { [Error: EACCES, mkdir '/home/colin/tmp/npm-10021-myBKjnB0'] npm ERR! stack: 'Error: EACCES, mkdir \'/home/colin/tmp/npm-10021-myBKjnB0\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! path: '/home/colin/tmp/npm-10021-myBKjnB0' } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! System Linux 3.8.0-37-generic npm ERR! […]

将上传的文件存储在Express Js的文件系统中

我是nodejs的新手,想知道如何把一个文件放到我的系统后台甚至上传到S3等 这里是文件对象: req.body { homeColor: 'black', guestColor: 'white', thirdColor: 'red', file: { webkitRelativePath: '', lastModifiedDate: '2014-05-05T02:26:11.000Z', name: '2014-05-05 10.26.11.jpg', type: 'image/jpeg', size: 1310720 }, title: 'tfuyiboinini' } 如何处理req.body.file,以便可以进行物理保存? 请帮忙,谢谢!

使用MEAN堆栈从服务器控制器获取请求

我使用MeanJs使用MEAN堆栈。 问题是,我有一个任务需要从服务器端(Expressjs)调用GET请求到另一个服务器(使用不同的域名)。 客户端(AngularJs)中的代码调用: $scope.getWorkflow = function() { $http.get('/ezee', $scope.credentials).success(function(response) { console.log(response.message); }).error(function(response) { console.log('error'); }); }; 而相应的服务器控制器function是: exports.list = function(req, res) { req.get('http://ezslave.io', function(q, r){ res.json({message: r.message}); // just to test }); }; 显然,下面的代码不起作用。 我不确定如何从listfunction进行GET请求。 我是否应该使用ExpressJs或纯粹的NodeJs? 以及如何获得正确的库加载?

如何区分经过身份validation的用户在客户端与Passport和node.js?

我使用Passport.js与MongoStore进行身份validation,我使用express作为Web框架。 一旦用户login,他就可以访问某个路线上的内容。 我想提供不同的内容,取决于哪个用户已authentication 。 比方说,在Mongo的members集合中,每个members都拥有一个category或privileges属性,然后我将决定向他展示什么。 我将使用AngularJS来绑定和呈现HTML。 这是我的路线pipe理: app.get('/',function (request, response) { if(request.isAuthenticated()) response.redirect('/admin') else response.sendfile("public/index.html") }) app.get('/admin',function (request, response) { if(request.isAuthenticated()) response.sendfile("views/admin.html") else response.redirect('/') }) app.post('/login', passport.authenticate('local', { successRedirect: '/admin', failureRedirect: '/' }) ) app.get('/logout', function (request, response){ request.session.destroy(function (err) { response.redirect('/'); //Inside a callback… bulletproof! }) }) app.get('*',function (request, response) { response.redirect('/') }) 这是我的Passport.js代码: […]

生产节点应用程序无法findSVG文件

在我的本地开发应用程序中,使用下面的代码(花括号embeddedAngular.jsvariables),svg文件显示得很好: <img ng-src="img/servant_{{servant.personality}}.svg" draggable="false"> 但是当部署在Heroku上时,SVG文件会产生一个404: Failed to load resource: the server responded with a status of 404 (Not Found) Angularvariables在生产站点上工作,图像地址是准确的。 所以,这不是问题。 相反,我认为我的Node / Express应用程序可能无法提供SVG文件。 也许这是一个Heroku问题? 仅供参考我正在使用MEAN堆栈。 这是我的公用文件夹的configuration: //Setting the fav icon and static folder app.use(express.static(config.root + '/public')); 图像在 public/img 有什么想法吗?