Tag: angularjs

在进行数据库调用时,如果控制器响应返回JSON对象,则无法在view.ejs中打印JSON对象值

我有通过控制器查询数据库的JSON响应,我想在view.ejs文件中打印这个JSON对象值。 view.ejs <div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng-repeat="x in names"> <td>{{ x.username}}</td> <td>{{ x.password}}</td> </tr> </table> </div> <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.get("") .then(function (response) {$scope.names = response.users;}); }); </script> 这是我的模型User.js module.exports = { autoCreatedAt: false, autoUpdatedAt: false, attributes: { username:{ type:'string', required: true, unique:true }, password:{ type:'string', required:true }, […]

如何在页面中包含AngularJS

我正在做一个NodeJS应用程序,我想用我的客户端脚本AngularJS。 我通过NPM下载了AngularJS,现在我试图让它在我的页面中实现,出于某种原因,我的请求不起作用。 任何人都可以帮我包括AngularJS文件? 发布页面。 extends layout block content script(src="/javascripts/postCtrl.js") // Page Content .container(ng-app='postModule', ng-controller='postCtrl') form(method='post') button(ng-click='test()') Click to test Button 发布脚本 var angular = require('angular'); var app = angular.module('postModule', []); app.controller('postCtrl', function ($scope, $sce) { $scope.test = function(){ alert("Working"); }; });

在angularjs中访问nodejs cookie

我正在构build一个简单的web应用程序,使用nodejs作为后端与angularjs前端。 使用nodejs,我在用户login后设置了一些cookie。 res.cookie(name,value) 我为用户名和user_id创build了两个cookie。 当我看到设置的cookie,使用 res.json(req.cookies) 和JSON响应有实际的user_id和另一个关键connect.sid ,也许是因为我使用连接闪光灯,我不知道。 但是当我使用$ cookies.get('user_id')访问angularjs中的cookie时,这个值是一些编码值, 例如:对于实际的user_id: 571be8d34666cf69664645d5 , 我越来越j%3A%22571be8d34666cf69664645d5%22 我怎样才能得到实际的用户ID? 我知道真正的ID是在string之间,我可以通过使用一些string操作来得到它,但有另一种方法。 我在我的应用程序中使用passportjs,express-session,connect-flash,connect-mongo,cookieparsing器。

如何使用AngularJS从NodeJS“获得”

我开始了一个AngularJs应用程序,并从数据库中检索一些数据我使用NodeJS(对我来说是全新的),在NodeJS的控制台上工作,也直接在浏览器中inputURL,但当我尝试获取所需的信息AngularJS中的http.get()在浏览器中使用相同的URL我找不到404。 我想这将是一个Cors问题,所以我补充说 require('cors') in the nodeJS app and still doesn't work 任何人都可以帮助我吗? 我正确地为前端的Angularjs和后端的NodeJS制作单独的应用程序,还是应该只在一个应用程序中组装它们? 感谢您的帮助 这是AngularJS代码: $scope.keyLoad = function () { $http.get("localhost:8080/product") .success(function (response) { $scope.keys = response; console.log(response) }) }; $scope.keyLoad();

Nodejs Express不加载脚本文件

我试图通过节点快递运行一个angular度的应用程序。 1文件结构 AngularNode public /core.js /index.html project.json server.js 2 server.js var express = require('express'); var app = express(); app.get('*', function(req, res) { res.sendfile('./public/index.html'); // load the single view file (angular will handle the page changes on the front-end) }); // listen (start app with node server.js) ====================================== app.listen(8000); console.log("App listening on port 8000"); 3 index.html […]

为什么我的$ http.post返回400错误?

我对“平均数”相当陌生,如果这个问题如此明显,那么很抱歉。 我想要发送电子邮件给联系人,当他们点击一个发送button。 我处理发送电子邮件的代码是使用一个post,我正在使用SendGrid Nodejs API来发送电子邮件。 问题是我一直运行到400 Post Error。 这是我在Google Chrome控制台中遇到的错误 这是我在服务器端得到的错误 这是在我的controller.js中: $scope.send = function(contact) { console.log("Controller: Sending message to:"+ contact.email); $http.post('/email', contact.email).then(function (response) { // return response; refresh(); }); }; 这段代码在我的server.js中: var express = require("express"); var app = express(); //require the mongojs mondule var mongojs = require('mongojs'); //which db and collection we will be […]

HTTP POST v / s HTTP GET

我想从前端(Angular)到后端进行数据库查询。 但是我需要发送很多参数。 据我所知,如果我们不做任何数据库更改,最好使用GET,因为它使用caching的条目。 如果需要在服务器/数据库上进行更改,则应使用POST。 但是如果我想发送很多参数(一些是序列化的对象)并且不做任何服务器端改变,那么在这种情况下使用POST请求是否可以,并且将所有参数embedded到POST正文中而不是发送巨大的URL编码的GET请求?

奇怪的cors与套接字问题

我正在使用btford.socket-io,并尝试与节点交谈。 它工作正常,但不是我从localhost:5000更改为example.org如下所示: .factory('socket',function(socketFactory){ //working var myIoSocket = io.connect('http://localhost:5000'); //not working var myIoSocket = io.connect('http://example.org:5000'); mySocket = socketFactory({ ioSocket: myIoSocket }); return mySocket; }) 我在我的控制台中得到了这个错误 XMLHttpRequest cannot load http://example.com:5000/socket.io/?EIO=3&transport=polling&t=LIGH5VO. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access. The credentials mode of […]

如何发送post请求到cloud9中的server.js

您好,我正在学习云9上的平均堆栈。 我已经到了试图将variables发送到我的node.js服务器的地步,但是我不确定我的服务器是否正在拾取它。 我的发布请求代码是否有明显的错误? app.js(前端angular) console.log('begin'); var http = new XMLHttpRequest(); var params = "text=stuff"; http.open("POST", "https://new-backup.splacorn.c9.io/myApp/server/server.js/", true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function() { console.log('onreadystatechange'); if (http.readyState == 4 && http.status == 200) { alert(http.responseText); } else { console.log('readyState=' + http.readyState + ', status: ' + http.status); } } console.log('sending…') http.send(params); console.log('end'); 这是我得到的控制台响应: begin sending… end […]

TypeError:无法读取未定义的属性“findAll”

我正在开发一个使用angularjs,nodejs和postgresql的web应用程序。 我在我的数据库中有两个表,一个用于库存,另一个用于客户端。 我结合我的index.js文件,在我的路线文件夹,其中两个表都有一个findAll函数。 当我把这两个表的引用index.js,一次只有一个工作。 这里是两个表使用的模板,包括findAll: exports.getobjects = function(req, res) { models.Object.findAll().then(function(objectss){ res.json(objects); }); }; 有没有人做了我想要做的事情? 更新:这里是整个index.js文件: /* * GET home page. */ var models = require("../models"); exports.index = function(req, res) { res.render('index', { title : 'title' }); }; /* clients */ exports.getclients = function(req, res) { models.Client.findAll().then(function(clients){ res.json(clients); }); }; exports.saveclients = function(req, res) { […]