Tag: angularjs

当我将数据保存到mongoDB时,如何获得_id值到我的代码中

在angular度上,代码是 $scope.add = function(work){ if (work == "") { return; }; $scope.todos.push({work: work, done: false}); var todos = $resource("/todo"); todos.save({work: work , done: false}, function() { alert("Successfully added"); }); $scope.work = ""; } 在后端,我用express写这样的代码。 router.post("/",function(req, res) { var collection = db.get("todo"); collection.insert({ work: req.body.work, done: req.body.done }, function(err, todos) { if(err) throw err; res.json(todos); }) […]

从node.js中以angularjs的forms使用json数据作为后端和sql数据库

我正在devise一个简单的应用程序,它在后端有一个node.js服务器,前面有一个angularjs。 我使用这样的代码来获取一个简单的GET请求来从sqldb获取一些信息: req.execute('view_proc').then(function (recordsets) { if (recordsets) { res.write(JSON.stringify(recordsets)); console.log(recordsets); result_send = { is_logged: true, }; 我使用json.stringify将数据发送到angularjs。 以下是angularjs中的获取请求: $http.get('/api/views/123').success(function(data,status,headers,config){ }). error(function(data,status,headers,config){ }); 我想知道如何在angularjs中使用JSON数据,并希望json数据以angularjs显示。

如何将plunker连接到本地Node.js服务器?

我想将我的plunk连接到在本地机器上运行的节点服务器。 我想实现这个目的是为了从数据库中获取一些数据。 目前,我已经在我的plunk上的app.js文件中创build了一些示例数据。 有没有办法做到这一点? 如果不是,那么有什么替代方法可以在线运行Node.js应用程序?

如何在Express.js中添加一个Angular 2应用程序作为视图

我正在Angular 2中创build一个应用程序,需要从服务器上运行的脚本获取数据。 为了做到这一点,我试图添加我已经存在的Angular应用程序作为视图到一个快速的应用程序,就像这里所做的那样。 我按照教程中给出的说明初步设置了文件夹结构,但是本教程没有介绍如何实际连接Angular和Express应用程序,以便在使用npm start时将它们一起运行。 然后,我发现另一个build议使用快速/angular生成器 ,我最终安装生成这个package.json文件的职位: { "name": "support-dashboard", "version": "0.0.0", "dependencies": { "express": "~3.0.0", "ejs": "~0.8.4" }, "devDependencies": { "connect-livereload": "~0.2.0", "grunt": "~0.4.1", "grunt-concurrent": "~0.3.0", "grunt-contrib-clean": "~0.4.1", "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-compass": "~0.3.0", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-connect": "~0.3.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-cssmin": "~0.6.0", "grunt-contrib-htmlmin": "~0.1.3", "grunt-contrib-imagemin": "~0.1.4", "grunt-contrib-jshint": "~0.6.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-watch": "~0.4.0", "grunt-google-cdn": "~0.2.0", "grunt-karma": "~0.4.3", […]

如何提供图像到客户端nodejs和angular度

我试图发送.jog图像到客户端,但我失败了。 app.get('/image', function(req, res){; res.sendfile(path.resolve(path.resolve(__dirname,'/Imagepath/image.jpg"))); }); 在我的angular度上 $http({ method:'GET', url:'/image', }).then(function (response){ $scope.image= response.data; }) <img id="imgid" ng-src="{{image}}" width="500" height="400"/> 问题是响应是一些二进制数据。 我怎样才能把它发送给我可以显示在img src上的数据。 如何在客户端的服务器文件夹中显示图像?谢谢。

不能npm安装karma-ng-html2js-preprocessor

我已经发现了一个恼人的问题关于标题模块。 当我安装karma-ng-html2js-preprocessor时,它总是以下面的错误结束: >fsevents@0.2.1 install /Library/WebServer/Documents/node_modules/fsevents >node-gyp rebuild …… nam WARN karma@0.10.10 requires a peer of karma-chrome-launcher but none was installed. …… 问题的原因是什么? 除了使用这个包之外,还有其他方法可以对templateUrl进行unit testing吗? 谢谢

无法从express.js加载静态文件

我是node.js和后端编程的新手。 我无法从快速加载静态文件。 我没有使用“公共”目录。 我需要从“js”文件夹的js文件。 这是文件夹结构文件夹结构: 在index.js中我提到了: app.use('/js',express.static(__dirname + '/js')); index.html: <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/sngulsr.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.1.3/ui-bootstrap.min.js"></script> <script type="text/javascript" src="js/angular-routing.js"></script> <script type="text/javascript" src="js/angular-main.js"></script> <script type="text/javascript" src="js/controllers.js"></script> <script type="text/javascript" src="js/custom.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootstrap-tpls.js"></script> (这些是没有得到加载的文件) 所以,当我运行该文件,我得到$未定义的错误,因为jquery没有得到加载。 编辑:删除__dirname从app.use图像EDITED_IMG

部署到heroku – 未能检测到buildpack nodejs(jasonswett)

我正在学习Jason Swett的“Angular for Rails Developers”一书。 主题在第2章:部署。 首先我做了这个: $ rm -rf public $ ln -s client/dist public 然后在heroku中创build应用程序后,我添加了buildpack $ heroku buildpacks:add https://github.com/jasonswett/heroku-buildpack-nodejs $ heroku buildpacks:add heroku/ruby 这是build筑物的结果 === author-wizard Buildpack URLs 1. https://github.com/jasonswett/heroku-buildpack-nodejs 2. heroku/ruby 这是package.json文件 { "name": "author-wizard", "version": "0.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "start": "ng server", "postinstall": "typings install && ng build", […]

POST请求使用angular$资源

在我的index.js文件中,我有以下POST … router.route('/bears') // create a bear (accessed at POST http://localhost:8080/api/bears) .post(function(req, res) { var bear = new Bear(); // create a new instance of the Bear model bear.name = req.body.name; // set the bears name (comes from the request) // save the bear and check for errors bear.save(function(err) { if (err) res.send(err); res.json({ message: […]

后端文件被公开加载 – Angularjs / Node / Gulp

我一直在努力知道为什么我的后端文件被加载为前端文件。 当我正在用angular + node + gulp工作一个新项目时,对我来说似乎有些困惑。 这里有一个例外的图像..任何build议? 图像错误