Tag: angularjs

Angular Node – 在打开新的浏览器窗口时向服务器发送令牌

这个问题是不言自明的:我有一个令牌存储在我的浏览器。 当我login时,服务器端authentication中间件使用Passport来authentication我。 但是,当我closures并重新打开浏览器窗口时,令牌仍然存在,但护照不知道我是谁。 我怎样才能从客户端到服务器端检索令牌? 以下是我的代码。 app.get('/main', ensureAuthenticated, function(req, res, next) { // thingToSend gets sent the first time, I will modify it // later so it doesn't resend token if token exists var thingToSend = { token: createSendToken(req.user, config.secret), id: req.user._id, username: req.user.username, authorization: req.user.authorization }; res.render('main.ejs', thingToSend); }); function ensureAuthenticated(req, res, next) { if […]

AngularJS将数据从multipartForm指令丢失到路由

我正在尝试构build一个Excelfile upload器,并parsingpath中的数据来存储它,但是在通过$ http服务路由发送的FormData中,数据会丢失。 我不知道该怎么做! 如果您有任何经验,请帮忙! Html查看: <form ng-controller="myCtrl"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" ng-model="myFile.name"> </div> <div class="form-group" > <input type="file" file-model="myFile.file"/> </div> <button ng-click="Submit()">upload me</button> </form> 控制器视图: myApp.controller('myCtrl', ['$scope', 'multipartForm', function($scope, multipartForm){ $scope.myFile = {}; $scope.Submit = function(){ var uploadUrl = '/upload'; multipartForm.post(uploadUrl, $scope.myFile); } }]); 服务视图: myApp.service('multipartForm', ['$http', function($http){ this.post = function(uploadUrl, […]

将使用loopback-component-passport的用户angular色设置为内置模型

我正在尝试使用npm loopback-component-passport来创build基于条件的用户, 如果用户有属性isAdmin:true他应该有adminangular色 如果用户有属性isAdmin:false他应该有userangular色 这是我的代码: if (form.$valid) { AuthService.register({ name: $scope.user.name, email: $scope.user.email, password: $scope.user.password, isAdmin: $scope.user.isAdmin }) .then(function() { // Account created, redirect to home $state.go('home'); }) .catch(function(err) { err = err.data; $scope.errors = {}; // Update validity of form fields that match the mongoose errors angular.forEach(err.errors, function(error, field) { form[field].$setValidity('mongoose', false); $scope.errors[field] = […]

如何从$$状态对象获取数据

$ scope.packgs总是作为一个$$状态对象结束,但如果我控制台响应它是正确的数组对象,我期待着,我做错了什么? 我的控制器 routerApp.controller('PortalController', ['$scope', '$state', 'UserService', 'PackageService', function($scope, $state, UserService, PackageService) { $scope.isLoggedIn = UserService.isLoggedIn; $scope.currentUser = UserService.currentUser; $scope.logOut = UserService.logOut; $scope.packgs = PackageService.get($scope.currentUser()).success(function(response){ return response; }); /*if($scope.packgs === null){ $scope.errorMessage = "You are not tracking any packages, add some to your portal!"; }*/ console.log($scope.packgs); }]); 我的工厂 packages.get = function(info){ return $http.get('/api/packages?owner='+info).success(function(data){ packages.data = […]

我如何写一个JSON对象通过节点服务器文件?

我正在使用Angular作为前端,并尝试将JSON对象写入与index.html相同的目录中名为“post.json”的文件。 我可以使它使用PHP,但我想知道如何与Node.js。 我在网上看了很多post,但也许我不了解http POST实际上是如何工作的,以及服务器需要从Angular应用程序写入文件的设置。 如何从Angular应用程序写入文件以及节点服务器需要什么设置? 代码在Angular文件中: // Add a Item to the list $scope.addItem = function () { $scope.items.push({ amount: $scope.itemAmount, name: $scope.itemName }); var data = JSON.stringify($scope.items); $http({ url: 'post.json', method: "POST", data: data, header: 'Content-Type: application/json' }) .then(function(response) { console.log(response); }, function(response) { console.log(response); }); // Clear input fields after push $scope.itemAmount = […]

Electron + angularjs IPC机制

我正在尝试在Electron中使用AngularJs。 我感到困惑的是, 这里的电子文档build议使用类似于: // In renderer process (web page). const ipcRenderer = require('electron').ipcRenderer; console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong" ipcRenderer.on('asynchronous-reply', function(event, arg) { console.log(arg); // prints "pong" }); ipcRenderer.send('asynchronous-message', 'ping'); 但是由于Angular在浏览器(webkit)中运行,我不能使用require来获取ipcRenderer。 如何克服这个问题。

启动npm时出错?

我是新的Angular2,当我尝试启动npm服务器与npm start项目的文件夹内我得到这些错误 > angular2-authentication-sample@0.0.1 start /home/no-one/Desktop/Frontend > npm run front > angular2-authentication-sample@0.0.1 front /home/no-one/Desktop/Frontend > webpack-dev-server –inline -d –colors –display-error-details –display-cached –port 3000 sh: 1: webpack-dev-server: Permission denied npm ERR! Linux 3.19.0-51-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "front" npm ERR! node v5.6.0 npm ERR! npm v3.7.3 npm ERR! code ELIFECYCLE npm ERR! angular2-authentication-sample@0.0.1 front: […]

使用Strongloop无法从s3获取特定文件

我可以上传,删除,并从容器(S3)获取文件夹列表,但不能从亚马逊S3使用Strongloop获得特定的文件。 我的代码: $scope.getS3Files = function(myfolderName){ //have to get all zip files in myfolderAbc $http.get('api/basePath/containerABC/files/folder1/myfolderAbc=' + myfolderName).then(function (result) { $scope.filePath = result.data; }, function (err) { toastr.error(err.data.error.message); }), }; 错误: message: "Shared class "basePath" has no method handling GET /containerABC/files/folder1/myfolderAbc=myfolderName" name: "Error" stack: "Error: Shared class "basePath" has no method handling GET /containerABC/files/folder1/myfolderAbc=myfolderName↵ at restRemoteMethodNotFound (d:\NodeJSProjects\abc\node_modules\loopback\node_modules\strong-remoting\lib\rest-adapter.js:322:17)↵ […]

如何使用Node / Angular / JavaScript将多个图像上传到亚马逊AWS S3存储桶

我想知道电子​​商务网站如何以及在哪里上传他们产品的图片。 Amazon AWS S3存储桶有多好? 我们如何使用Node / Javascript / Angular一次性上传/获取多个图像。 请build议。 谢谢

Angular.js和Node.js – 通过控制器将inputvariables传递给server.js

现在刚刚学习了MEAN栈,我正在摆弄它,但我有点迷路。 我想实现的是利用一个外部的API来自动填充关于最初input的标签的input字段。 所以问题是,如何将foo的值一直传递给server.js以进行调用? 最终用户input一个tag并按下“获取数据” 控制器将tag的值(在我的.ejs文件中定义为ng-model="object.tag" )传递给getData路由 server.js获取tag并将其传递到外部API URL中进行调用 外部API做它的事情,为我返回一个漂亮和漂亮的JSON文件。 控制器自动填充尽可能多的表单字段,因为它可以从返回的JSON。 这里有一些代码位,所以你可以理解我有更多的结构: –index.ejs– <input type="text" ng-model="object.tag" /> <button ng-click="grabFooInfo()">Get Data</button> –controller.js– $scope.grabFooInfo = function(){ $http.get('/getData').success(function(res){ // Will do stuff here after data comes back }); }; –server.js– app.get('/getData', function (req, res) { var options = { host: 'my.api.im.calling.com, path: '/v1/fooApi/' + // #Need foo here // […]