Tag: angularjs

PUT /更新操作在$资源AngularJS客户端在基于rest的应用程序(mongoose插入/更新问题)失败。

我是新的MEAN应用程序。在这里我有一个基于REST的示例应用程序使用节点宁静的库中,我可以执行操作(获取,保存,删除),除了“放”。 然而,“放”操作在rest客户端(先进的REST,邮递员)上运行良好,但不在angular客户端上运行。 mongoose模型 var restful = require('node-restful'); var mongoose = restful.mongoose; //架构 var productSchema = new mongoose.Schema({ 名称:string, 学院:string, 年龄:数量 }); //返回模型 module.exports = restful.model('Products',productSchema); 节点expression代码 var express = require('express'); var methodOverride = require('method-override'); var mongoose = require('mongoose'); var bodyParser = require('body-parser'); var cors = require('cors'); // MongoDB mongoose.connect( '的mongodb://本地主机/ rest_test'); var autoIncrement = require('mongoose-auto-increment'); […]

Nodejs和express路由,如何处理客户端的承诺

我试图做一个单一的路由来回mongodb,但似乎在客户端,我不能检索数据从$资源收到的承诺。 在HTML页面上有一个button,点击下面的函数: $scope.getToken = function() { console.log('$scope.getToken()'); authenticationService.getToken($scope.data.email).then(function(result) { $scope.data.token = result; }); } 收到的结果是: 对象“m”,字段为0:“j”,1:“6”,2:“o”,3:“p”,4:“E”,5:“7”,6:“X” 7:“t”,$ promise:d,$ resolved:true, proto :Object 正如你所看到的,我收到了生成的令牌,数据库似乎工作正常,并调用函数。 客户端收到答案的服务有一个function: function getToken(userEmail) { var deferred = $q.defer(); $resource(baseUrl + '/getToken').save({ email : userEmail }, function(result, error) { if(result) { deferred.resolve(result); } else { deferred.reject(error); } }); return deferred.promise; } 发送这个的服务器端的function: var router […]

从index.html调用函数,函数无限循环

我试图做一个function,只显示了一个具有正确angular色的用户的一部分的HTML。 这些是我的function: 的NodeJS / server.js app.get('/api/isadmin', ensureAuthenticated, function (req, res) { User.findById(req.user, function (err, user) { res.send(user); }); }); 这是问题发生的地方,它会无情地运行: <ul ng-if="isAdmin()"> <li> <a ui-sref="admin">Admin</a> </li> </ul> 为什么发生这种情况? 我已经看过了卫星的isAuthenticatedfunction,基本上做了同样的事情。 编辑:更新的代码: adminservice.js angular.module('App') .factory('AdminService', function ($q, $http, toastr) { return { getAdmin: function () { var httpget = $http.get('http://localhost:3000/api/isadmin'); httpget.then(function (response) { var res = response.data.role; […]

Expressjs / AngularJS:执行req-flash后出错

我像这样实现了req-flash: https : //www.npmjs.com/package/req-flash 。 这样做后,出现以下错误: D:\_SOURCES\smfc\node_modules\req-flash\index.js:36 if (options.locals) { ^ TypeError: Cannot read property 'locals' of undefined at module.exports (D:\_SOURCES\smfc\node_modules\req-flash\index.js:36:13) at Object.<anonymous> (D:\_SOURCES\smfc\routes\index.js:6:13) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:16:19) at Object.<anonymous> (D:\_SOURCES\smfc\app.js:15:14) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at […]

angular色应用$ http请求到本地主机上的节点应用

我在localhost:3000上运行nodejs应用程序。 我有一个前端教程的angular度页面,像这样调用localhost … $scope.msg = 'requesting'; $http({ method: 'GET', url: 'http://localhost:3000/' }).then(function(response) { $scope.msg = response; }, function(response) { $scope.msg = 'err ' + JSON.stringify(response); }); 我可以从我的节点应用程序的控制台上看到它正在回答200和一个json对象{foo:'bar'} 。 但$scope.msgvariables最终看起来像这样… err { "data":null, "status":-1, "config":{ "method":"GET", "transformRequest":[ null ], "transformResponse":[ null ], "url":"http://localhost:3000/", "headers":{ "Accept":"application/json, text/plain, */*" } }, "statusText":"" } 为什么客户认为服务器产生了良好的响应时会出现问题? 在浏览器中运行请求正常工作。 加载浏览器开发工具的angular度页面( http:// localhost:9000 […]

使用Angular $资源执行获取请求时出错

我正在做一个函数,以执行get请求到指定的路由,发送一个string到后端,以返回一些基于该string的结果,我得到这个错误: 错误:[$ resource:badcfg]资源configuration错误。 预期的响应包含一个数组,但有一个对象 这里是angular部分: 视图: <input type="text" data-ng-model="searchStr"> <textarea> {{responseData}} </textarea> 按Ctrl: $scope.$watch('searchStr', function (tmpStr) { if (!tmpStr || tmpStr.length == 0) return 0; // if searchStr is still the same.. // go ahead and retrieve the data if (tmpStr === $scope.searchStr) { Search.get({ 'search': $scope.searchStr }) .$promise.then(function(data) { $scope.responseData = data; }) } […]

angular.js – TypeError:无法读取未定义的属性'then'

我正在尝试使用我的服务插入每个捕获的详细信息页面。 虽然当我尝试加载我的服务中的一个id页面(例如: /capture/5740c1eae324ae1f19b7fc30 )我得到未定义,使用此代码: app.factory('captureApi', ['$http', function($http){ var urlBase = 'URL'; // ==> Gives back an array as such: //[ //{ // "_id": "5740c1e3e324ae1f19b7fc2f", // "created_at": "2016-05-21T20:15:38.554Z", // "userId": "118000609287736585411", // "place": "place", // "birdname": "birdname", // "__v": 0 //}, //{ // "_id": "5740c1eae324ae1f19b7fc30", // "created_at": "2016-05-21T20:15:38.554Z", // "userId": "118000609287736585411", // "place": "place", // "birdname": […]

显示基于特定loginID的button

现在,如果用户没有login,我可以隐藏这个button,当用户使用html页面中的ng-show标签login时,它会显示出来。 但是我想要的只是当用户使用特定的loginIDlogin时显示的button。 例如:ng-show =“currentUser”,其中email == example01@gmail.com或currentUser.exeexample01@gmail.com。 我不知道这是如何工作,但我该怎么做呢? loginfunction function login(email, password) { return User .login({email: email, password: password}) .$promise .then(function(response) { $rootScope.currentUser = { id: response.user.id, tokenId: response.id, email: email }; }); } HTML <button type="button" ng-show="currentUser" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">Send sms for selected </button>

AngularJS http获得settimeout逻辑

我有一个问题,公司之一有这么多的数据,加载这么长的时间,以显示在我的AngularJs项目。 有时,当连接种类被切断或请求超时时,它不会出现。 那时,我的客户要显示一些消息,并重新运行该函数来重新加载数据。 后端正在使用NodeJS。 请帮助我如何充分满足我客户的要求。 这是我的代码从后端获取数据。 $scope.tableParams = new ngTableParams({ page: 1, // show first page count: 20, // count per page sorting: { title: 'asc' // initial sorting }, filter: { title: filterText, is_active: $scope.IsActive } }, { total: 0, getData: function ($defer, params) { companyService.getDataBelongToCompany($scope.companyId, params.url()).then(function (data) { params.total(data.total); $defer.resolve(data.jobs); $scope.collapsed = false; […]

将Express NodeJS的值传递给AngularJS控制器variables

我想从快速NodeJS服务器传递一些值到AngularJS控制器variables。 这里是代码片段…. 服务器 app.post('/run-engine', function(req, res){ console.log(req) res.writeHead(200, {'Content-Type': 'text/html'}); fs.readFile('index.html', 'utf-8', function(err, content) { if (err) { res.end('error occurred'); return; } var reconData = 'some temp'; //here I assign temp variable with needed value var renderedHtml = ejs.render(content, {data: reconData}) res.end(renderedHtml); }); }); HTML代码片段 <section class="mdl-layout__tab-panel tab2" id="scroll-tab-2"> <div class="page-content"> <h1>This is Tab2</h1> Data: […]