Tag: angularjs

如何简化发送(文件,模型)的angular度和FormData

我有一大堆文本字段和一个文件字段的forms。 我使用Mulder来接收文件,而且工作正常。 我已经设法在请求中包含所有必要的数据,但是我对我的解决scheme不满意。 有没有更好的方式来附加窗体的参数,而不是手动指定每个字段? $scope.createJob = function() { var fd = new FormData(); fd.append("logo", $scope.logo); fd.append("title", $scope.formData.title); fd.append("title", $scope.formData.description); fd.append("title", $scope.formData.hiringOrganization); fd.append("title", $scope.formData.jobLocation); fd.append("title", $scope.formData.url); $http.post('/api/v1/jobs', fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined} }) .success(function(data) { console.log(data); }) .error(function(data) { console.log('Error: ' + data); }); }; 正如你所看到的,我附加了formData对象的每个参数。 我试过了 fd.append(“body”,$ scope.formData); 但是我结束了string“[Object object]”。

父级ng-click事件后,angular度子级ng-click事件不会触发

我对Angular来说很新颖,所以我还没有想出所有的小怪癖。 目前我有一个button,用ng-click =“open()”打开覆盖。 在叠加层中还有另一个button,用ng-click =“close()”closures叠加层。 现在看来,ng-click事件如果另一个事件在视图中则不会触发。 如果存在ng-click =“open()”,则ng-click =“close()”不会触发,反之亦然。 下面是我正在谈论的一个简单的版本,因为我正在对实际的应用程序进行一些处理: 视图 <button ng-click="open()">Open</button> <div id="overlay"> <button ng-click="close()">Close</button> </div> 调节器 $scope.open = function(){ //some move.js to open the overlay } $scope.close = function(){ //some move.js to close the overlay } 叠加层不是dynamic生成的,而是呈现给页面加载。 下面是@sz tech提供的解决scheme。 不是$编译方法。 http://codepen.io/NicholasByDesign/pen/WwqMXa?editors=1010 只是一个方面说明,因为我不认为这将有所作为。 我在一个nodejs和jade环境中工作。 我把它作为普通的HTML,省去了封装了打开/closuresfunction的控制器代码来简化事情。

成功付款后redirect到AngularJS路线

我正在整合PayUMoney应用程序在我的意思是堆栈应用程序。现在付款成功完成payumoney调用我的成功api。 现在我需要将这个api调用的响应呈现给我的angularjs视图页面。 我怎么能做到这一点?

使用Angular / Nodejs将表单数据发布到MongoDB数据库

我对AngularJS比较陌生,我决定构build一个基本的博客应用程序,以熟悉MongoDB并使用$ http请求。 不过,使用我的Angular服务将用户填充到$scope的表单中的数据发布到我的MongoDB数据库时遇到了一些麻烦。 最初,我把$ http请求放在我的控制器中。 这适用于我: mainCtrl.js $scope.addPost = function() { $http.post('/api/blogs', $scope.formData) .success(function(data) { $scope.formData = {}; $location.path('blogs'); console.log(data, 'Blog created.'); }) .error(function(data) { console.log('Error: ' + data); }) }; 但是这是通过我的控制器完成的,而且我明白这不是最佳实践,所以我试图将这个function放在一个Angular服务中。 以下是构成应用程序的这部分代码的相关部分,包括HTML视图: server.js //Dependencies. var express = require('express'); var router = express.Router(); var bodyParser = require('body-parser'); var cors = require('cors'); var mongoose = require('mongoose'); […]

如何使用MEAN堆栈在注册时显示失败消息

我正在开发一个使用护照authentication进行login和注册过程的SPA。 事情是,一切工作正常,我甚至可以显示成功通知,但我不能find一种方式来显示错误通知,以防用户做出不好的操作。 这是我在passport-init注册的代码: passport.use('signup', new LocalStrategy({ passReqToCallback : true }, function(req, username, password, done){ var email = req.body.email; User.findOne({$or: [ {username: username}, {email: email} ] }, function(err, user){ if(err){ return done(err, false); } if(user) { console.log('username or email already taken '+req.body.username); return done(null, false, {message: 'Username or email already taken.'}); } user = new User(); […]

如何正确地将node_modules移动到不同的位置

我试图将我的node_modules移动到不同的位置,我所做的是删除node_modules,并将package.json移动到我希望它被安装的位置,然后运行npm install ,其中安装了node_modules,但是现在,如果我运行npm start ,服务器启动,我得到了很多错误: (index):5 GET http://localhost:3000/node_modules/bootstrap/dist/css/bootstrap.min.css (index):9 GET http://localhost:3000/node_modules/es6-shim/es6-shim.min.js (index):10 GET http://localhost:3000/node_modules/systemjs/dist/system-polyfills.js (index):12 GET http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js (index):13 GET http://localhost:3000/node_modules/systemjs/dist/system.src.js (index):14 GET http://localhost:3000/node_modules/rxjs/bundles/Rx.js (index):15 GET http://localhost:3000/node_modules/angular2/bundles/angular2.dev.js (index):16 GET http://localhost:3000/node_modules/angular2/bundles/http.dev.js (index):21 Uncaught ReferenceError: System is not defined(anonymous function) @ (index):21 我更新了index.html文件,以使用根目录node_modules中的文件而不是当前目录的node_modules。 还有什么我应该做的,以使其工作? 请注意,index.html与node_modules位于不同的目录中

使用Sequelize,NodeJS和AngularJS创build具有n:m关系的logging

更新 :我已经进一步了。 请看post的底部 我正在开发一个基于sql-fullstack yeoman生成器的项目,并且已经使用包含的示例代码作为指导。 事情进展顺利,大部分,但我现在在一个场景,我有两个表/模型与双向N:M关系: 任务组: module.exports = function(sequelize, DataTypes) { var TaskGroup = sequelize.define("TaskGroup", { taskGroupID: { field: "TaskGroupID", type: DataTypes.INTEGER, allowNull: false, unique: true, autoIncrement: true, primaryKey: true }, name: { field: "Name", type: DataTypes.STRING, allowNull: false }, description: { field: "Description", type: DataTypes.STRING }, modifiedBy: { field: "ModifiedBy", type: DataTypes.STRING } […]

如何searchJSON对象以查找特定的参数值?

我有一些JSON,看起来基本上是这样的: { "inactive_user": { "name": "A", "id": "1", "dob": "01011990", }, "active_staff": { "id": "B", "dob": "2", }, "active_student": { "name": "C", "pid": "3", "dob": "01011990", }, "no_securityquestion": { "name": "D", "pid": "4", "dob": "01011990", } } 我想要做的是,基于从请求中给出的id,返回具有该id的用户(inactive_user,active_staff等)。 我怎样才能做到这一点? 我到目前为止所尝试的是: for (var parent in userObject){ if(userObject.parent.pid === pid){ console.log(userObject.parent); reply(userObject.parent); } } 但userObject.parent(其中userObject是整个JSON文件)只是返回未定义,这是奇怪的,因为父将返回文件中的父对象的每个名称(inactive_user和什么不)

npm作用域包和私有registry

我们公司已经为我们的软件包build立了一个私有的npmregistry。 我们正在尝试设置一个angular2应用程序,并且所有包含的angular度包(从angular2教程页面)都被限定了范围。 问题是,当npm被设置为我们的私人registry,一个npm install给我们这个错误消息: npm ERR! Linux 4.4.8-boot2docker npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" npm ERR! node v4.3.0 npm ERR! npm v2.14.12 npm ERR! code E404 npm ERR! 404 no such package available : @angular/core npm ERR! 404 npm ERR! 404 '@angular/core' is not in the npm registry. npm ERR! 404 You should bug the […]

用户注册为非活动状态,并通过OTP激活

以下是authenticationstream程的步骤: 用户通过input他的详细信息进行注册,他将被发送一个OTP到他的邮件。 此时用户的详细信息存储到mongoDB。 通常在validationOTP之后,用户可以login到应用程序。 但在我的情况下,validationOTP之前,用户可以login到应用程序。 如何解决这个请帮助我。 我的一些代码如下所示。 model.js var UserSchema = new Schema({ name: String, email: {type: String, required: true, select: true}, mobile: {type: String, required: true, select: true}, password: {type: String, required: true, select: true}, }); controller.js vm.submitPost = function(userData){ $http({ url: 'http://192.168.2.8:7200/api/pages/auth/register', method: 'POST', data: userData }).then(function(res) { if(res.data.success){ $location.path('/pages/auth/otp'); } else { […]