我有一个写在angularJS上的应用程序,由grunt构建.有没有办法可以从节点js创建一个http服务器并在那里托管它.请分享任何有用的代码段或文档.谢谢
httpserver node.js angularjs single-page-application gruntjs
我正在使用一个使用节点回调约定的节点模块.我想使用Bluebird承诺将此模块转换为API.我没有得到如何做到这一点.
下面是我的节点样式回调函数.我想将它转换成蓝鸟的可靠承诺.
var module = require('module'); // for example xml2js, or Mongoose
var parseString = xml2js.parseString;
parseString(xml, function (err, result) { // the regular API
if (err) {
console.log("Error in generation json from xml");
} else {
return result;
}
});
Run Code Online (Sandbox Code Playgroud)
我试过这种方式,PromisifyAll但它不起作用:
var module = Promise.promisifyAll(require('module')); // for example xml2js
xml2js.parseString(xml)
.then(function (result) {
console.log("result = ", result);
})
.catch(function (err) {
console.err(err);
});
Run Code Online (Sandbox Code Playgroud)
我收到了then is not a function错误.我该如何解决?
我有一个用例,我必须使用CSS隐藏HTML元素,如下所示:
HTML:
<div class="item">
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.item {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要在页面加载后使用ng-show切换元素的可见性,如下所示:
<div class="item" ng-show="show_element">
</div>
Run Code Online (Sandbox Code Playgroud)
但是,即使$scope.show_element设置为true,元素也不会变得可见,也就是说,css属性会覆盖AngularJS的ng-show.有没有办法让ng-show更优先?
此外,您可能认为我$scope.show_element最初可以保持虚假隐藏它.但是在这种情况下,当页面加载时,我会很快看到元素,这从UX的角度来看并不好.
离子模态带有slide-in-up. 我们可以将动画更改为fade-in吗?
我在角度和laravel中构建一个API服务,当我向API发出GET调用时,Everythings工作正常,但是当我触发POST调用时,服务仍然使用GET方法而不是POST.那是我的服务:
function LeadsAPI($http,$q,BASE_URL)
{
this.updateLead = function (lead_data) {
var url = BASE_URL+"/leads/update/";
var deferred = $q.defer();
$http.post(url , lead_data).then(function(response){
deferred.resolve(response.data);
});
return deferred.promise;
}
}
Run Code Online (Sandbox Code Playgroud)
我从控制器调用此函数:
LeadsController.$inject = ['$scope', 'LeadsAPI'];
function LeadsController($scope , LeadsAPI)
{
LeadsAPI.updateLead({'lead_id' : res._id, 'the_lead': {'fist_name' : 'asd asd'}}).then(function (res) {
console.log(res);
});
}
Run Code Online (Sandbox Code Playgroud)
我尝试将参数作为字符串传递("a = b&c = d ...")并添加标题:
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
Run Code Online (Sandbox Code Playgroud)
在run我的应用程序模块实例化的功能,但是,我不断收到405 (Method Not Allowed)错误.任何想法为什么以及如何解决它?非常感谢你们!:)
我在尝试将徽标放在 RMarkdown 文档的标题时遇到问题。
这就是我所拥有的
---
output: html_document
---
<style type="text/css">
body, td {
font-size: 16px;
font-family: "Gills Sans TM";
}
code.r{
font-size: 12px;
font-family: "Gills Sans TM";
}
pre {
font-size: 12px
font-family: "Gills Sans TM";
}
</style>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在右上角添加徽标
我写了一个名为'cardViewer'的角度指令,它可以用动画显示其中的图像.
按"上一步"按钮时,图像向左滑动.按"下一步"按钮时,图像向右滑动.
我尝试这样做ng-switch,只支持.ng-enter和.ng-leave动画类.但是我需要两种方式进入(从左和右进入),两种方式离开(左和右).
所以我试着ng-class解决这个问题.我希望它可以toLeft在切换之前添加类,因此它可以应用特定的css动画.
但它似乎无法正常工作.当我按两次"下一步"按钮时,它工作正常.但是当我按下"下一步",然后按"上一步",新图像进入正确方向,但旧图像离开方向错误.
我的指令模板:
<h1>hahaha</h1>
<div>
<button ng-click='prev()'>prev</button>
<button ng-click='next()'>next</button>
</div>
<div>current Card Index: {{displayCard}}</div>
<div class="card-container" ng-switch="displayCard">
<img class="card"
src="http://i.imgur.com/EJRdIcf.jpg" ng-switch-when="1"
ng-class="{'toLeft': toLeft, 'toRight': toRight}"/>
<img class="card"
src="http://i.imgur.com/StaoX5y.jpg" ng-switch-when="2"
ng-class="{'toLeft': toLeft, 'toRight': toRight}"/>
<img class="card"
src="http://i.imgur.com/eNcDvLE.jpg" ng-switch-when="3"
ng-class="{'toLeft': toLeft, 'toRight': toRight}"/>
</div>
Run Code Online (Sandbox Code Playgroud)
指示:
angular.module('app', ['ngAnimate'])
.directive('cardViewer', function() {
return {
templateUrl: 'cardViewer.html',
link: function(scope, element, attr) {
scope.toLeft = false;
scope.toRight = false;
scope.displayCard = 1;
//when …Run Code Online (Sandbox Code Playgroud) javascript angularjs ng-switch angularjs-directive angularjs-animation
我正在尝试使用Nagios的check_http插件监视Web服务.
我试图监控的网址包括url参数.
事实证明check_http插件在检查时会忽略url参数.
这是我的配置.
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
define service{
use local-service ; Name of service template to use
host_name pear
service_description HTTP
check_command check_http!-u http://pear.com/total?eId=12345&env=abcde
notifications_enabled 0
}
Run Code Online (Sandbox Code Playgroud) 我理解在简单场景中使用promises但是当前在使用for循环和对本地sqlite数据库进行一些更新时如何实现某些东西时确实很困惑.
代码如下
surveyDataLayer.getSurveysToUpload().then(function(surveys) {
var q = $q.defer();
for (var item in surveys) {
var survey = surveys[item];
// created as a closure so i can pass in the current item due to async process
(function(survey) {
ajaxserviceAPI.postSurvey(survey).then(function(response) {
//from response update local database
surveyDataLayer.setLocalSurveyServerId(survey, response.result).then(function() {
q.resolve; // resolve promise - tried only doing this when last record also
})
});
})(survey) //pass in current survey used to pass in item into closure
}
return q.promise;
}).then(function() {
alert('Done'); …Run Code Online (Sandbox Code Playgroud) 这个分页可能会有一点错误.表格中的日期未随页面链接的更改而更新
<uib-pagination
ng-model="currentPage"
total-items="rows.length"
max-size="maxSize"
boundary-links="true">
</uib-pagination>
Run Code Online (Sandbox Code Playgroud)
我想在项目列表的最后一项上添加点击事件.
<li ng-repeat="item in items" ng-click="myFunction" >{{item.name}}</li>
$scope.myFunction = function(){
// logic here...
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个新的 angular 应用程序并使用工厂,但是当我收到一个错误时
错误:[$injector:undef] http://errors.angularjs.org/1.4.5/ $injector/undef?p0=Data at Error (native) at https://ajax.googleapis.com/ajax/libs/ angularjs/1.4.5/angular.min.js:6:416 在 Object.$get ( https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:32 ) 在 Object.e [as invoke] ( https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:39:96 ) 在https://ajax.googleapis.com /ajax/libs/angularjs/1.4.5/angular.min.js:40:410 在 d ( https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:38 :308 ) 在 e ( https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:39:64) 在 Object.g.instantiate ( https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:39:213 ) 在 b.$get ( https://ajax. googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:80:257 ) 在 s ( https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route .min.js:12:165 )
var app = angular.module('testapp', ['ngRoute']);
app.config(['$routeProvider',
功能($routeProvider){
$routeProvider.
当('/用户列表',{
title: '所有用户列表',
templateUrl: 'userlist.html',
控制器:'列表用户'
})
.when('/个人资料',{
title:'用户详情页面',
templateUrl:'profile.html',
控制器:'listuser'
})
。除此以外({
重定向到:'/用户列表'
});
}])
app.factory("数据", … angularjs ×9
javascript ×4
promise ×2
animation ×1
api ×1
asynchronous ×1
bluebird ×1
callback ×1
css ×1
factory ×1
gruntjs ×1
html ×1
http ×1
httpserver ×1
monitor ×1
nagios ×1
ng-repeat ×1
ng-show ×1
ng-switch ×1
node-modules ×1
node.js ×1
pagination ×1
r ×1
r-markdown ×1
rstudio ×1
web-services ×1
xml-parsing ×1