Tag: angularjs

如何使用grunt连接angularjs文件

我有一个angularjs应用程序。 我想连接所有的angularjs文件到单个文件。 我正在使用grunt并search关于连接grunt插件。 我发现有grunt-contrib-concat和grunt-concat-in-order插件。 但是,我无法find关于如何连接依赖文件的例子的答案。 请让我知道如何使用grunt-concat-in-order插件指定依赖关系。 注意:在grunt-concat-in-order文件中,它指出了指定framework.require(“moduleA”)。 但不知道什么框架。 有没有什么有效的方法来指定一个文件中的依赖关系? 在此先感谢Rajaguru

如何在angularjs中访问由passportjs设置的cookie

我真的希望这不是一个愚蠢的问题,但我怀疑是这样。 我search了一切可以理解的事情,但是我仍然不明白如何阅读使用nodejs / express / passport设置的cookie。 我使用Angular的ngCookies和$ cookies服务,但是当我尝试打印出我在服务器端设置的cookie时,我看到了这个(使用console.log($ cookies [“connect.sess”])) s:j:{"passport":{"user":{"id":1,"email":"xxxxxx@yyyy.com","role":"Admin"}}}.0lKpQzpgzCAjgkIayDkUiOLhktIYsohr61U/4xSwWFA 我的cookie在那里。 但是,它们都是作为一个string存储的。 我应该看一个不同的对象吗? 它不会让我访问 – > $cookies["connect.sess"].passport 因为这是不明确的,因为$ cookies [“connect.sess”]返回一个string。 任何提示,我要去哪里错了? 我需要做的就是访问服务器中设置的这些cookie。 我不需要改变它们。 我希望在这方面额外的眼睛会做的伎俩。 我很难过 我尝试通过使用res.cookie设置我自己的cookie。 在我创buildcookie的服务器端,它看起来很好。 但是在那里和angular度之间,它看起来像“j:{我的json曲奇}”这次没有:前面,没有结束的gobble-de-gook。 当然,我可以parsing这些东西,并find我的JSON,但这东西得到补充,为什么? 我做了一些戳动作和快速response.cookie添加j:如果你传递一个对象json的前面。 和s:与json对象之后的blurb是他们签名cookie的方式。 所以我发现我真的不需要护照发送的会话cookie。 我可以使用会话cookie中的userid在服务器端进行身份validation,并使用以下命令创build自己的电子邮件和angular色cookie: res.cookie("email", user.email, {my cookie options}) res.cookie("role", user.role, {my cookie options}) 而不是尝试用json对象填充会话cookie。 我在下面select的答案是我所知道的最好的select。 虽然我觉得很难相信你必须从字符上去掉字符才能正确地获取客户端的cookies。 似乎很奇怪。 我是一个cookie新手,所以如果任何人有一个解释或阅读的好链接,我很乐意听到它。

grunt ngtemplates任务100%cpu

咕噜任务ngtemplates运行无限期(近一个小时,没有完成)与100%的CPU利用率。 如果我评论这个任务,那么构build完成。 然后在ngtemplates中创build任务,并在另一台机器上完成OK。 任何想法/线索都非常感谢。 节点版本:0.10.29 grunt-cli:v0.1.13 grunt:v0.4.5 ngtemplates: { app: { cwd: '<%= yeoman.app %>', src: ['views/{,*/}*.html', 'views/inbox/{,*/}*.html' , 'scripts/directives/*.html'], dest: 'scripts/templates.js', options: { usemin: 'scripts/scripts.js', // <~~ This came from the <!– build:js –> block htmlmin: { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, removeComments: true, // Only if you don't use comment directives! removeEmptyAttributes: […]

Grunt将angular度ui路由器模板连接成一个文件

我有一个有150个文件的angular-ui-router项目。 我想写一个咕噜的任务,把它们全部合并成一个index.html像这样: <script type="text/ng-template" id="path-to-file-1.html"> Content of file-1.html here </script> <script type="text/ng-template" id="path-to-file-2.html"> Content of file-2.html here </script> <script type="text/ng-template" id="path-to-file-3.html"> Content of file-3.html here </script> … 我正在考虑使用https://github.com/outaTiME/grunt-replace,但我想尽可能做到这一点。 我目前的想法: 的index.html <body> @@path-to-file-1.html @@path-to-file-2.html @@path-to-file-3.html </body> gruntfile.js replace: { dist: { options: { patterns: [ { match: 'path-to-file-1.html', replacement: '<%= grunt.file.read("path/to/file-1.html.html") %>' }, { match: 'path-to-file-2.html', […]

MEAN堆栈Facebook授权错误:没有“访问控制允许来源”标题?

我正在尝试在我的MEAN堆栈应用程序上进行Facebook授权。 我正在使用passport和passport-facebook 。 我不使用jade或ejs ,我想使用纯粹的angularjs。 当我运行我的应用程序,并点击“login”button,我得到以下错误: XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…2Flocalhost%3A3030%2Fauth%2Ffacebook%2Fcallback&client_id=…. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3030' is therefore not allowed access. 我做了一些研究,发现node cors模块可以解决这个问题,但是没有。 我做错了什么,我该如何解决? 这里是我的routes.js文件(服务器端): app.get('/auth/facebook', passport.authenticate('facebook')); app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/success', failureRedirect: '/error' })); app.post('/success', function(req, res, next) { User.findById(req.session.passport.user, function(err, user) { if(err){ res.send({success:false}); }else{ res.send({success:true,user: user}); } […]

如何从angularjs传递一个条形标记到nodejs或修复错误nodejs后?

我试图设置条纹支付,但遇到了一个错误:TypeError:无法读取未定义的属性“ID” 在/Users/andreykondratyuk/websites/talllly/src/server/app.js:56:37 在Layer.handle [作为handle_request] … 表格: <form stripe-form="stripeCallback" name="checkoutForm"> <input ng-model="number" placeholder="Card Number" payments-format="card" payments-validate="card" name="card" /> <input ng-model="expiry" placeholder="Expiration" payments-format="expiry" payments-validate="expiry" name="expiry" /> <input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" /> <button type="submit">Submit</button> <div ng-if="checkoutForm.card.$invalid"> Error: invalid card number! </div> </form> 在控制器中 // Stripe Response Handler $scope.stripeCallback = function (code, result) { console.log(result); if (result.error) […]

如何设置编码file upload

我正在使用angular度file upload ,当我上传一个非TXT的文件,如图片,PDF或DOC文件,我尝试下载,文件是不同于我上传的文件看图片),我不确定这是否是因为上传文件时出现错误的编码。 左边的文件是原始文件。 客户端: var uploader = $scope.uploader = new FileUploader({ scope: $scope, url: '/file/upload/', method:'POST', headers: { 'X-XSRF-TOKEN': 'some token' } }); $scope.upload = function(){ uploader.queue.forEach(function(item){ item.formData = [ {'filename': 'friendlyName' }, {'objectType': 'element' }, {'elementId': 'someId'} ]; }); uploader.uploadAll(); }; 后端POST … 在这里,busboy文件事件中的编码variables是'7bit' .. exports.uploadDocument = function(req,res){ req.pipe(req.busboy); var doc = new […]

时刻15日

我开发一个简单的应用程序,显示每日预算,直到下一次付款。 为此,我正在使用momentJS。 问题是我的应用程序中的逻辑是错误的。 我先find哪一天,然后find这个月的第一天( date(1) ),然后我总结1个月和14天。 但是,无论何时下个月(如现在-02/12),当然会告诉我,未来的15日是在2月份。 长话短说,我如何find未来的第15个使用时刻? 这是我的申请: $scope.nextDate = moment().date(1).add(1, "months").add(14,"days"); //calculate when is the next 15th $scope.difference = Math.floor(moment.duration($scope.nextDate.diff($scope.today)).asDays()); 提前致谢!

如果脚本失败,NPM应该继续执行更多的脚本

我有我的package.json文件中的脚本,我在我的CMD执行npm运行量angular器 : "scripts": { "postinstall": "bower install", "pretest": "npm install", "test": "karma start test/karma.conf.js", "test-single-run": "karma start test/karma.conf.js –single-run", "preupdate-webdriver": "npm install", "update-webdriver": "webdriver-manager update", "preprotractor": "npm run update-webdriver && node setUp.js", "protractor": "protractor test/protractor-conf.js", "postprotractor": "node tearDown.js", } 如果我所有的e2etesting都通过了,那么npm会运行整个脚本 – 也就是我的tearDown.js。 但是,如果我的量angular器testing(“量angular器”:“量angular器testing/ protractor-conf.js”)失败,npm不会继续执行我的postprotractor文件(我需要tearDown.js,因为它closures我的后端) 。 有没有使npm运行整个脚本的任何解决scheme?

使用Angular.js处理基于OAuth令牌的authentication?

我已经在Node.js中设置了我的后端代码,使用护照成功validationGitHub。 我能够使用jsonwebtoken生成一个标记。 但是,由于OAuth的stream动,我无法pipe理前端。 如果这是基于他们input电子邮件和密码的forms,则视图可能有点像这样: <form ng-submit="login()"> <input ng-model="user.email" type="email" name="email" id="email" ng-required /> <input ng-model="user.password" type="password" name="password" id="password" ng-required /> <button type="submit">Log in</button> </form> 在此stream程中,控制器可以使用login()向路由发出请求,并在成功时接收包含currentUser和令牌的对象,并在callback中redirect。 OAuth的stream程在这里造成了一些麻烦。 在OAuth中,您将用户redirect到站点之外,并返回到服务器上设置currentUser的node.js端的callbackURL。 我不知道如何将angular度前端连接到这个过程。 在angular度,你应该如何处理这个,点击一个“Githublogin”button将更新$window.sessionStorage.tokenvariables和$rootScope.currentUser对象?