Tag: angularjs

在controller.js文件中处理AngularJS中的错误

我有单页NodeJS + AngularJS应用程序。 有一些领域要填写文字。 在controller.js中,我想检查一个或多个字段是否为空,以便在浏览器中发送错误警报。 我的controller.js文件: var myApp = angular.module('myApp', []); myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http) { console.log("Hello World from controller"); //$http.get('/builder').success(function(response){ // $scope.PEM = response; //}); $scope.sendParts = function(){ var bool = true; for(var prop in $scope.pem){ if(prop == 'undefined'){ bool = false; break; } if(bool){ $http.post('/builder', $scope.pem).success(function(response){ $scope.PEM = response; }); } else{ […]

如何编译Node.js和Angular

我将在一个包含Node.js,Angular和Mongo DB的项目上工作。 我在.Net环境中工作了15年以上,这对我来说将是一个新的世界。 所以我有几个问题。 什么IDE推荐Node.js和Angular? 我很舒服使用Visual Studio,我注意到VS有扩展,所以我可以使用它的Node.js和Angular。 它具有智能感知和显示编译时错误。 是VSbuild议还是有更好的IDE可用? 来自.Net世界,所有.Net项目必须在部署之前进行编译。 这是不是真的Node.js或Angular项目? 我们不需要编译它们? 我注意到我的团队成员只是复制整个文件夹(有代码)prod服务器,就是这样。 没有编译,没有bin文件夹,没有释放文件夹。 我计划使用jenkins部署,所以如果第二个问题是真的,那么我想我只需要编写脚本,将代码复制到目的地。 (并根据环境相应地操作configuration文件)

angular度种子量angular器抛出错误

我尝试在我的电脑上运行angular-seed(Windows 10,上次更新) https://github.com/angular/angular-seed 。 networking工作正常,但我有量angular器的问题。 噶运行,但是当我尝试量angular器> npm运行量angular器时,我得到这些错误。 E:\angular-seed>npm run protractor > angular-seed@0.0.0 preprotractor E:\angular-seed > npm run update-webdriver > angular-seed@0.0.0 preupdate-webdriver E:\angular-seed > npm install npm WARN install Couldn't install optional dependency: Unsupported > angular-seed@0.0.0 postinstall E:\angular-seed > bower install > angular-seed@0.0.0 update-webdriver E:\angular-seed > webdriver-manager update selenium standalone is up to date. chromedriver is […]

如何使angular度asynchronous调用同步调用?

我有一个应用程序显示内部进程的状态。 它也有一个单独的视图,允许你build立新的logging。 要build立一个新的logging,你填写一个表格,并提交一个电话是对我的nodejs服务器: 将logging插入到表中 启动一个存储过程 将您转回到状态页面 这里的问题是,页面在这种情况下挂起,因为有时存储过程需要一两分钟才能运行。 所以你等了几分钟,然后路由回状态页面。 现在,我实际上并不在意在前端看到这个存储过程的退出代码,因为您可以在状态页面上看到它的状态。 我想知道是否有办法让我启动这个过程,但是没有前端关心这个回报。 我已经尝试在$http调用服务器之前添加$location.path() ,但是$http调用永远不会发生。 有任何想法吗? 谢谢!

如何定义不包含静态资源的默认路由

我想使用express.js为单页面应用程序(angular度核心)定义一个默认path。 当请求静态文件并且在路由中不存在时会出现问题。 在这种情况下,将返回默认页面内容而不是404状态(未find)。 示例代码: var path = require('path'); var express = require('express'); var app = express(); var router = express.Router(); router.use(express.static(path.join(__dirname, '/scripts'))); router.get('*', function(request, response) { response.sendFile(path.join(__dirname, 'views/index.html')); }); app.use(router); app.listen(80); 是否存在一个很好的解决scheme来排除静态文件的默认路由并正确处理状态404? 将文件URL而不是通配符的正则expression式是一个好方法吗?

未使用Angular $ HTTP读取JSON文件在MEAN.JS应用程序中获取

我正在开发一个带有MEAN.JS(www.meanjs.org)的Web应用程序,我正在尝试在我的控制器中使用带有JSON文件的AngularJS $ HTTP Get请求,这样我就可以在我的一个页面。 出于某种奇怪的原因,JSON文件(foo.json)从不读取。 即使我只是尝试通过http:// localhost:3000 / foo.json达到文件,它不显示。 它也没有显示在任何错误控制台。 我把JSON文件放在我的模块,根目录,视图目录等任何地方,你把它命名。 只有当我使用像“modules / core / json / foo.json”这样的更长的path名时,我会得到Chrome控制台错误:“无法加载资源:服务器响应状态为404(未find)”错误。 这是我的控制器代码: angular.module('core').controller('FooController', ['$scope', '$http', function ($scope, $http) { $http.get('foo.json').success(function(data){ console.log(data); $scope.products = data; }); } ]); FOO.JSON文件放置在我的Core模块文件夹的根目录中,在视图中,甚至在应用程序的根目录中。 [ { "id" : 3, "name": "Orange Theme", "description": "Consectetur adipiscing elit. Vestibulum condimentum turpis nec nunc scelerisque convallis. Pellentesque […]

MEAN Stack:如何将函数的结果更新到数据库?

我有一个评论系统,我需要将upvote存储在数据库中,每当upvote图标被点击。 function我增加了数量,但一旦我刷新它再次说0。 如何将其直接存储到数据库? 这里是代码: 在public / javascripts目录中的ang.js中: var app=angular.module('peopleComments',['ui.router']); app.factory('comments',['$http', function($http){ var c={ comments:[] }; //loading all existing comments with getAll() c.getAll=function(){ return $http.get('/comments').success(function(data){ angular.copy(data, c.comments); }); }; //function which creates the new comments for updating in the database c.create = function(comment) { return $http.post('/comments', comment).success(function(data){ c.comments.push(data); });}; return c; }]); app.controller('Base',[ '$scope','comments',function($scope,comments){ $scope.comments=comments.comments; $scope.addComment=function(){ […]

在Electron中运行时,有angular应用会中断

我开始构build一个Electron应用程序,当我尝试运行里面的angular度分布时,遇到了一些问题。 对于angular度的应用程序,我使用yeoman和咕噜build设。 如果我用grunt serve开发angular度应用程序并在localhost:9000上运行,那么Electron应用程序可以很好地select应用程序。 但是,如果我运行grunt构build,并将Electron应用程序指向静态文件,则会出现一些angular度错误。 [$injector:modulerr] Failed to instantiate module clientApp due to: Error: [$injector:modulerr] Failed to instantiate module ngResource due to: Error: [$injector:nomod] Module 'ngResource' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 在电子应用程序运行一个服务器与快递,我也试图挑选运行angular应用程序通过express在localhost:8000。 […]

我怎样才能得到凉亭和咕噜咕噜添加angular-bootstrap用户界面依赖?

我正在学习node.js,并尝试使用自动化工具来pipe理AngularJS应用程序。 为此,我在centos 7 devbox中安装了nodejs,grunt,yeoman和bower,并正在试验我在新环境中创build的AngularJS应用程序。 我怎样才能得到凉亭添加angular-bootstrap ui依赖于我在这个环境中构build的AngularJS应用程序? 在我的应用程序中的bower.json和Gruntfile.js都是自动生成的,所以我毫不犹豫地编辑它们,没有一些指导。 我曾经试过的是什么: 到目前为止,我浏览到/path/to/workspace/client并键入bower install angular-bootstrap 。 该命令成功运行。 但是,在应用程序的index.html ,bower生成的依赖关系列表不包含angular-bootstrap ui依赖关系,即使在编辑器中closures了index.html之后,键入Ctrl-C来停止服务器,然后键入grunt serve来启动服务器再次在编辑器中重新加载index.html 。 index.html的bower生成的依赖项列表如下所示: <!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <base href="/" /> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <!– Place favicon.ico and apple-touch-icon.png in the root directory –> <!– build:css(.) styles/vendor.css –> <!– bower:css –> <!– endbower –> […]

在Cloudant DBsearchAPI中使用angularjs和node.js后端

我正在尝试使用searchAPI从我的node.js后端search我的云数据库,然后显示网页上返回的内容。 我正在使用一个angular度MVC,我有点新,所以很抱歉,如果这有点简单。 我有一个包含这个HTML的前端 – <button class="btn btn-default" ng-click="getDataandHeadings()"></button> <table> <tr ng-repeat="doc in myData"> <td>{{doc.doc.TerritoryTypeName}}</td> <td>{{doc.doc.TeamOwnerSerialNo}}</td> <td>{{doc.doc.TeamOwnerName}}</td> <td>{{doc.doc.TeamOwnerNotesID}}</td> <td>{{doc.doc.SellerSerialNo}}</td> <td>{{doc.doc.SellerName}}</td> <td>{{doc.doc.SellerNotesID}}</td> </tr> </table> 控制器 – 'use strict'; var app = angular.module('app', false); app.controller('greetingscontroller', function($scope, $http) { $scope.getDataandHeadings = function() { $http.get('/retrieve').success(function(data) { $scope.myData = data; }).error(function(err) { //handle the error }); }; }); 后端节点应用程序 – var […]