Tag: angularjs

使用DOM中的信息创build控制器/服务来保存数据

在angular度,我有一个视图中的项目列表将显示在另一个视图取决于他们是否被检查。 这是您查看您想要显示在另一个视图中的运动的视图 <ion-item ng-repeat="sport in sports" ng-init="sport.checked = true" ng-click="sport.checked = !sport.checked"> {{:: sport.name}} </ion-item> 这是另一种观点 <div ng-show="sport.checked" ng-repeat="sport in sports"> {{sport.name}} </div> 正如你所看到的那些运动有一个ng-init = sport.checked = true ,所以所有的运动都在开始时显示,但是你可以不检查这些运动,直到你再次检查它们才能看到它们。 这是我迄今为止的工作,但一旦刷新页面,所有的检查和取消选中,一切刷新后重新启动,所以你知道我需要坚持数据库中的数据或东西,我使用node.js /sails.js以及Redis。 我对如何创buildnode.js部分中的几乎所有东西有一个想法,但是我需要在控制器和服务的Angular部分中提供一些帮助,所以我需要你的帮助。 我希望用户只能检查他们的运动一次,而不是每次login应用程序。 那么当运动没有被选中时,我可以向控制器添加哪些function,以便为服务提供build议,以及服务如何接收这些数据? 另外,如果您对NodeJS部分有任何build议,那也太棒了。

Heroku应用程序使用generator-angular-fullstack失败构build

我使用sudo grunt build我的应用程序。 没有错误。 dist文件夹是build立的,应用程序使用sudo grunt serve:dist 。 当我第一次尝试部署到heroku时,使用项目根目录下yo angular-fullstack:heroku失败。 我收到以下错误: Initializing deployment repo Creating heroku app and setting node environment Creating myapp… done, stack is cedar-14 https://myapp.herokuapp.com/ | https://git.heroku.com/myapp.git { [Error: Command failed: ! No app specified. ! Run this command from an app folder or specify which app to use with –app APP. […]

如何在已经存在的REST API后端的Angular应用程序中实现login系统

我的朋友和我正在build立一个应用程序 – 我的朋友是在后端(Node.js),我在前面。 他在他的最后实现了会话,并为我提供了我需要调用的URL来login。例如,一个POST请求 http://ourapp.heroku.com/login 用哪个username和password通过 在我这边,在Angular应用程序中,我创build了一个login页面,当单击Login时,它会调用一个Angular服务。 如果这个服务从服务器收到200 ,它会: $cookieStore.put(cookieNames.LOGGED_IN_COOKIE, true); $state.go('home', {}, {reload: true}); 问题是我们在前端的应用程序有奇怪的问题。 例如,login和登出通常不起作用。 而且,即使在注销之后,用户也能够访问页面。 我想(至less我觉得),我没有正确地存储从服务器接收到的Cookie,我只是存储我自己的。 整个Angular对我来说还是很奇怪的,因为在PHP或者Python应用程序中,你从客户端获得一个页面请求,并且在发送他请求的页面之前validation他是否已经login。 在Angular中是不同的 – 用户已经拥有了所有的页面。 那么,如何在不login的情况下限制他可以看到的内容以及如何正确跟踪服务器的cookie呢?

将消息绑定到angularjs视图

我正在做一个简单的聊天应用程序与客户端angular度和服务器side.onangular度我已经使用ngResource服务器端connection.messages传输完成,但问题是每当一个新的消息被添加到消息列表这是由ng-repeat显示,在chatbox浏览器中没有实时显示,需要刷新。 根据我的理解,这是因为在客户端包含了路由层,而不是在视图文件中使用ng-controller的指令,但是如何解决这个问题,是因为我也需要这个路由层。 任何有关这个帮助表示赞赏。

Nodejs通过id获取用户

我使用MEAN堆栈的app ,我有用户,我注册和login使用satellizer一切正常。 但是,当我尝试通过它的身份证get用户我什么也没有得到,我可以做请求获取所有用户,但不是通过身份证。 请注意使用Ionicframework作为forntEnd框架。 这里是我的后端的代码: app.get('/api/me', function(req, res) { User.findById(req.user, function(err, user) { console.log(req.user); console.log(user); res.send(user); }); }) 我的前端代码控制器: .controller('ProfileCtrl', function($scope, $http, $stateParams, $ionicLoading, $timeout, $stateParams) { $ionicLoading.show({ template: 'Loading…' }); $http.get('http://localhost:3000/api/me') .success(function(data) { console.log("Recived data via HTTP", data); $timeout(function() { $ionicLoading.hide(); $scope.user = data; }, 1000); }) .error(function() { console.log("Error while getting the data"); […]

获取EJS模板中的项目ID并注入服务

我想弄清楚如何传递一个Id到我的PlayerDetailController ,然后在我的服务中使用它。 我在我的主app.js有以下路线: var players = require('./routes/players'); app.use('/players', players); 我在players路线( routes/players.js )中有以下路线: var express = require('express'); var router = express.Router(); /* GET /players listing. */ router.get('/', function(req, res, next) { res.render('players', { title: 'Players', action: 'list'}); }); /* GET /player details. */ router.get('/:id', function(req, res, next) { res.render('players', { title: 'Player Details', action: 'details'}); }); […]

我可以在不使用node.js的情况下使用Ionic构build托pipe的Web应用程序吗?

我有兴趣使用Ionic构build一个Web应用程序。 标签,forms的东西,与angular.js集成…一切看起来 应该很好。 不过,Ionic也看起来是为Android和IOS创build本地应用程序。 它依赖于node.js的服务。 我只是将其托pipe在我客户的共享主机帐户上 – 我将无法获得node.js的工作。 我不打算开发应用程序使用任何服务,所以我不认为我需要node.js。 我打算通过http post与我的数据库进行通信。 我有兴趣知道 – 有什么理由我不会这样做? 如果我没有使用任何其他的方式与服务器通信,没有node.js,我会好吗? 有没有更好的select创build一个HTML5手机页面的网页应用程序? 我也不打算进入相机,加速计或任何types的东西,所以我不认为我也需要cordova。

在调用ng-click之后,对ng-class没有影响

HTML <div style="float:left" data-ng-repeat="x in tokens" ng-init="btnclass=false"> <button type="button" ng-class="{true:'btn btn-material-light-green btn-sm', false:'btn btn-material-grey btn-sm'}[btnclass]" ng-click="toggle($index)">{{x}}</button> </div> 控制器文件 $scope.toggle = function(i){ console.log("done"+i+" ",$scope.btnclass); $scope.btnclass=$scope.btnclass?false:true; console.log($scope.btnclass); } 控制台输出表明variablesbtnclass确实改变,但点击后我看不到button的颜色。 "done3 " true false "done3 " false true 编辑因为,很多人一直在质疑ng类expression式的语法,我想澄清这是一个古老的语法,它的工作原理。 引用这个问题 。

当通过ajax加载图像时,获得无限循环

我正在尝试使用户上传的文件在node.js中是私有的。 而且我正在使用angular来在客户端提供文件。 <div ng-repeat="message in messages"> <div class="details" ng-if="message.type == 'photo'"> <img ng-src="{{ chat_ctrl.getPhoto(message.photo, message.conversation_id, message.type) }}" class="message-photo" alt="{{ message.text }}"> <p>{{ message.text }}</p> <small am-time-ago="message.timestamp" am-preprocess="unix"></small> </div> </div> 这是我用来获取文件的function。 me.getPhoto = function(url, id, message_type){ if(message_type == 'photo'){ RequestsService.getPhoto(url, id).then(function(response){ console.log(response); //returns the data-uri of the image return response; }); }else{ return ''; } }; […]

Angular $ http POST从ExpressJS中获得null

我在后台没有经验,并与Node一起工作,尝试设置一个$ http POST请求来发送表单到Express。 每次发出请求时,我的callbackdata都是null 。 也许我的快车路线configuration不正确? 我正在使用Angular与Express / Node进行通信,通过nodemailer(我已经正确configuration)发送一封电子邮件。 这是我的$http POST请求: 客户端/服务/电子邮件/ emailer.js angular.module('public').factory('EmailerService',function($http) { return { postEmail: function(emailData, callback) { console.log('call http with object', emailData); $http({ method: 'POST', url: 'http://my-website.com/server/routes/emailer', data: emailData, headers: { "Content-Type": "application/json" }, responseType: 'json' }).success(function(data, status, headers, config) { console.log('success', data, status); }).error(function(data, status, headers, config) { console.log('error', data, […]