Tag: angularjs

closuresUrl上客户端的socket.io连接

我使用Socket.IO来绘制绘制图表的数据,在var socket = io.connect(); 我的节点js服务器的io.on('connection', function(socket){})启动一个函数,间隔每1秒它发出的数据连接的客户端。 我希望套接字closures从客户端和服务器的Url(远离应用程序)的变化应该停止发射数据。

如何填充字段是否为空string如果为空不需要填充?

我有一个应用程序,有大量的数据以前保存在mongoDB。 现在我需要填充一些信息,如果referencePeople不是空的string。 在我的应用程序referencePeople是stringtypes而不是mongoose ObjectIdtypes。 我不想改变我的模式。 有没有什么办法可以在填充之前检查referencePeople是否为空。 或者如果是空的,避免填充。 模式: var OrderSchema = new mongoose.Schema({ customer: {type: mongoose.Schema.Types.ObjectId,ref: 'Customer'}, referencePeople: String, // can be "" or "customer id" …… }); 试图咆哮的代码,但得到了一个exception铸造ObjectId失败的价值“”path“ID” exports.getOrders = function(req, res) { Order.find({}) .populate('customer') .populate({path: 'referencePeople', model: 'customer'}) .exec(function(error, orders) { if(error) { return res.status(400).send({msg: 'Error occurred while getting orders.', error: error}); } […]

如何stream式传输数据以提供进度条

我有一个NodeJS应用程序做一些计算,我想在客户端( AngularJS )填写一个进度条,显示完成的计算量。 现在我做这样的事情: 服务器端 : var compute_percent = 0; router.post('/compute', function(req, res) { myTask.compute1(function(result) { compute_percent = 33; myTask.compute2(function(result2) { compute_percent = 66; myTask.compute3(function(result3) { compute_percent = 100; res.json(result3); }); }); }); } router.get('/compute_percent', function(req, res) { res.json(compute_percent); } 客户端 angular.module('myApp').controller('myCtrl', function($scope, $interval, $http) { $interval(function() { $http.get('/compute_percent').success(function(result) { $scope.percent = result}); }, 500); […]

Kibana不加载样式表

我正在尝试从源代码构buildkibana 4.1。 我刚刚使用下载的代码 git clone -b '4.1' 'https://github.com/elastic/kibana.git' 然后安装所有的依赖使用 sudo npm install 然后我开始使用服务器 npm start kibana加载正常,但它正在加载任何CSS文件我得到404错误的所有样式表 GET http://localhost:5601/styles/main.css?_b=@@buildNum 404 GET http://localhost:5601/plugins/visualize/styles/main.css 404 GET http://localhost:5601/plugins/discover/styles/main.css 404 GET http://localhost:5601/plugins/dashboard/styles/main.css 404 GET http://localhost:5601/plugins/settings/styles/main.css 404 GET http://localhost:5601/components/collapsible_sidebar/collapsible_sidebar.css 404 GET http://localhost:5601/components/typeahead/typeahead.css 404 GET http://localhost:5601/plugins/markdown_vis/markdown_vis.css 404 GET http://localhost:5601/plugins/metric_vis/metric_vis.css 404 GET http://localhost:5601/plugins/table_vis/table_vis.css 404 GET http://localhost:5601/components/doc_table/doc_table.css 404 GET http://localhost:5601/components/visualize/visualize.css 404 GET http://localhost:5601/components/doc_viewer/doc_viewer.css 404 […]

angular色http发布数据对象不被节点服务器视为对象

我使用angular度在客户端执行一个职位的用户对象的服务器。 这个用户对象只是让我在一个对象中传递所有的用户信息,用户名,密码,电子邮件,名字等。 而不必将每个作为一个单独的variables。 我在chrome的开发人员工具中看到以下POST参数。 {"username":"adfasdfasdf","password":"12123123123"} 但是,在我的服务器端js数据来作为单独的variables。 而不是具有用户名和密码的对象。 因此,console.log('userData ='+ userData)行logging用户名。 而“完成”variables包含密码。 为什么我没有得到服务器端的对象? 客户端HTML <form class="form-signin", ng-submit="register()"> <input type="text" class="form-control" placeholder="Username" ng-model="user.username"> <input type="password" class="form-control" placeholder="Password" ng-model="user.password"> </form> 客户JS var pollControllers = angular.module('pollControllers', []); pollControllers.controller('RegisterCtrl', ['$scope', '$http', '$location', function($scope, $http, $location) { // This object is filled by the form $scope.user = {}; $scope.register = function() […]

MEAN.js:获取存储在MongoDB中的用户数

我只是试图使用MEAN.js提交一个查询到MongoDB。 我想获得Mongo中存储的用户数量。 (所有已经注册的用户的数量)。 我正在处理一个由学生编写的由几千个.js文件组成的MEAN.js网站。 我已经确定了两个文件可能相关: 应用程序/控制器/用户/ users.authentication.server.controller.js 它的function像exports.signup = function(req, res) {…}和exports.signin = function(req, res, next) {…} 。 我补充说: exports.userCount = function(req, res) { // use mongoose to get the count of Users in the database User.count(function(err, count) { // if there is an error retrieving, send the error. nothing after res.send(err) will execute if […]

我如何使用xampp的angularjs,但没有node.js服务器通信?

我为我的编程Web应用程序使用基本的xampp直到现在我已经使用php的相同。 但是现在我已经切换到了angularjs 没有nodejs的服务器通信教程,我看不到任何地方 因为我不习惯使用nodejs,因为现在我想要为web应用程序直接使用angularjs; 比如提取和添加数据到数据库中。 <body id="index" ng-app="notesApp" > <h1>Hello servers!</h1> <div ng-controller="maincntrl as cntrl" ng-repeat="todo in cntrl.items" class="item"> <div><span ng-bind="todo.label"></span></div> <div>- <span ng-bind="todo.author"></span></div> </div> <script> angular.module('notesApp',[]) .controller('mainCntrl',['$http', function($http){ var self= this; self.items = []; $http.get('/api/note').then(function(response){},function(errResponse){ console.error("error while fetching note"); }); }]); </script> </body> 这个代码不工作

从mongodb通过nodejs获取数据并将其转换为html页面

基本上,我想显示“雇员”收集到HTML页面的特定领域。 但即使在网上search了很多,我也无法这样做。 这里是server.js文件的路由部分: app.get('/fetching', function(req, res){ connection.fetcher(function(data) { res.render("testing.html",data); } ); }); 现在这是来自connection.js文件的部分: var fetcher= function(callback) { var mongodb = require('mongodb'); var MongoClient = mongodb.MongoClient; var url = 'mongodb://localhost:27017/HippoFeedo'; MongoClient.connect(url, function (err, db) { if (err) { console.log('Unable to connect to the mongoDB server. Error:', err); } else { console.log('Connection established to', url); // Get […]

Sails.js IO.socket不发射

我有一个AngularJS应用程序,我试图让套接字触发创build/删除我的数据库中的项目。 我从$资源切换到io.socket.post()使用自定义控制器方法('socketCreate'),但不知道为什么我的套接字callback没有触发。 Sails JS控制台logging新用户,创build新用户,angular度从套接字获取数据并刷新列表。 这一切正常工作,但是io.socket.oncallback不会触发。 我没有得到事件的正确性? angular度控制器: $scope.newUser = function() { io.socket.post('/users/socketCreate', {name: $scope.temp_user.name}, function( data, jwres ) { $scope.refreshUsers(); $scope.temp_user = {}; }); }; if( !io.socket.newUserListen ) { io.socket.newUserListen = true; console.log( io.socket.newUserListen ); io.socket.on( 'users', function onServerSentEvent( msg ) { console.log( 'users', msg ); }); io.socket.on( 'user', function onServerSentEvent( msg ) { console.log( […]

nodejs和restful api服务

我创build了一个没有nodejs用法的angularjs应用程序。 我正在使用“chrome-add server extension”在本地运行应用程序,并使用Bluemix云部署文件并运行应用程序。 我已经在Bluemix和http.get中创build了一个java服务来获得服务到我的前端。 但是我有时在前端面临CORS的问题。 所以我build议创build一个nodejs文件来获取服务并集成到angular度控制器而不是http get方法。 我的问题是,我不想在nodejs中创build服务器configuration,只需在nodejs(app.get)中获取服务并传递给angularjs控制器。 该应用程序已被Chrome扩展端口调用。 我写在nodejs服务器文件中的代码是, var express = require('express'); var app = express(); var express = require('express'); var app = express(); app.get('http://myblumemix-service.mybluemix.net/getDetails', function(req, res){ //code to bind the response to angular controller //alert(""); //console.log("got already running port successfully"); }); app.listen("http://127.0.0.1:8887/"); 但是我无法成功地得到angular度控制器的响应。 我的问题是,我们可以在不创buildWeb服务器的情况下使用nodejs,只将其余的响应传递给angular度模块。 因为我是新的节点和angular度,有没有这样做的例子?