首页
在线工具
搜索
1
Kuboard与KubeSphere的区别:Kubernetes管理平台对比
2
ShardingSphere使用中的重点问题剖析
3
Flowable工作流引擎源码深度解析
4
用AI生成的原型设计稿效果还可以
5
如何将Virtualbox和VMware虚拟机相互转换
杂谈与随笔
工具与效率
源码阅读
技术管理
运维
数据库
前端开发
后端开发
Search
标签搜索
Angular
Docker
Phabricator
SpringBoot
Java
Chrome
SpringSecurity
SpringCloud
DDD
Git
Mac
K8S
Kubernetes
ESLint
SSH
高并发
Eclipse
Javascript
Vim
Centos
Jonathan
累计撰写
86
篇文章
累计收到
0
条评论
首页
栏目
杂谈与随笔
工具与效率
源码阅读
技术管理
运维
数据库
前端开发
后端开发
页面
搜索到
17
篇与
的结果
2017-02-10
node-sass 安装卡在 node scripts/install.js 解决办法
node-sass 安装卡在 node scripts/install.js 解决办法 一个 node 项目里用到了 node-sass@3.8.0 ,安装的时候在这一步: > node-sass@3.8.0 install path/to/project/node_modules/node-sass > node scripts/install.js 一直卡住,至少有半个小时没反应,自己的 Mac 和腾讯云的服务器上都是这样 去看 node_modules/node-sass/scripts/install.js 的 代码 ,发现是要在 GitHub 上下载编译好的 node-sass 二进制包 ,去看 node-sass 的 Release ,平均在 2.5 MB 左右 于是明了了,GitHub 在国内访问本来就不稳定,然后还是用 request 去访问,就更慢了。看了一下,半个小时左右才下了 500 K 正好又在 这里 的 getBinaryPath() 可以设置二进制的位置。在这之前还要先知道自己的系统需要的版本。 用这行命令: node -p "[process.platform, process.arch, process.versions.modules].join('-')" 复制输出的结果,去 Release 列表 找到对应的版本,Ctrl+F 粘贴,找到那个文件,下载(必要的时候挂代理,浏览器下载通常都比 node 下载更快更稳定),然后文件存到一个稳定的路径,并复制路径(比如 ~/.node/.npm/node-sass/darwin-x64-48_binding.node,windows下拷贝到AppData\Roaming\npm-cache\node-sass对应的版本下 ) 在 ~/.npmrc 下面新增一行,新增 sass_binary_path 项并填入刚才的路径,比如 sass_binary_path=/home/ubuntu/.npm/node-sass/darwin-x64-48_binding.node 最后再去项目目录下: rm -rf node_modules/ && npm i
2017年02月10日
2017-02-10
部署angular2-start碰到的问题
部署angular2-Strat碰到的问题 基本都是墙的问题:下载不了- node-sass无法下载 通过node -p "[process.platform, process.arch, process.versions.modules].join('-')"查看系统对应的版本 https://github.com/sass/node-sass/releases 在官方下载对应的版本 selenium-server-standalone-2.53.1 下载问题 https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-win64.zip 下载问题存放到提示错误的目录内 https://github-cloud.s3.amazonaws.com/releases/25354393/63b38414-8ee8-11e6-86d9-7cd52823928c.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20170210%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20170210T081906Z&X-Amz-Expires=300&X-Amz-Signature=2285da35b200def61e6ee64102902a84c72fbb57a00f989b74ee3b69ce322a58&X-Amz-SignedHeaders=host&actor_id=5735392&response-content-disposition=attachment%3B%20filename%3Dgeckodriver-v0.11.1-win64.zip&response-content-type=application%2Foctet-stream 下载完重命名为对应的版本号如: chromedriver_2.26win32.zip 并解压和重命名解压文件chromedriver_2.26.exe
2017年02月10日
2017-02-04
安装 nrm 自由切换 npm 源 国内镜像提升下载速度
安装 nrm 自由切换 npm 源 国内镜像提升下载速度 基于 npm ,全局安装以后,你开源无缝快速切换几个源,提高下载速度,拒绝 loading ! 安装 npm install -g nrm 开源地址 https://github.com/Pana/nrm 使用 查看帮助 ➜ /Users/zhangzhi/code >nrm -h Usage: nrm [options] [command] Commands: ls list all the registries current show current registry name use <registry> change registry to registry add <registry> <url> [home] add one custom registry del|rm <registry> delete one custom registry home <registry> [browser] open the homepage of registry with optional browser test [registry] show response time for specific or all registries help print this help Options: -h, --help output usage information -V, --version output the version number 查看当前支持切换的源 ➜ /Users/zhangzhi/code >nrm ls npm ---- https://registry.npmjs.org/ cnpm --- http://r.cnpmjs.org/ * taobao - http://registry.npm.taobao.org/ edunpm - http://registry.enpmjs.org/ eu ----- http://registry.npmjs.eu/ au ----- http://registry.npmjs.org.au/ sl ----- http://npm.strongloop.com/ nj ----- https://registry.nodejitsu.com/ pt ----- http://registry.npmjs.pt/ 上面列出了可选的9个源,还用 * 号标记出了当前我使用的源 切换指定的源 假如现在我想把 taobao 源 切换成 eu 的镜像源( 貌似走的教育网,我也不确定速度是不是快,只是演示切换) ➜ /Users/zhangzhi/code >nrm use eu Registry has been set to: http://registry.npmjs.eu/ 切换后的源列表 ➜ /Users/zhangzhi/code >nrm ls npm ---- https://registry.npmjs.org/ cnpm --- http://r.cnpmjs.org/ taobao - http://registry.npm.taobao.org/ edunpm - http://registry.enpmjs.org/ * eu ----- http://registry.npmjs.eu/ au ----- http://registry.npmjs.org.au/ sl ----- http://npm.strongloop.com/ nj ----- https://registry.nodejitsu.com/ pt ----- http://registry.npmjs.pt/ 可以看到源已经切换成了 eu 你还可以添加已知的源,或者删除
2017年02月04日
2017-01-22
AngularJS中的Provider们:Service和Factory等的区别
AngularJS中的Provider们:Service和Factory等的区别 引言 看了很多文章可能还是不太说得出AngularJS中的几个创建供应商(provider)的方法(factory()、service()、provider())到底有啥区别,啥时候该用啥,之前一直傻傻分不清楚,现在来总结一下。 下文中的术语说明: 供应商 ==> 泛指provider 服务 ==> 泛指service provider ==> provider()方法创建的东东 service ==> service()方法创建的东东 先说说供应商($provide) $provide服务负责告诉Angular如何创造一个新的可注入的东西:即服务。服务会被叫做供应商的东西来定义,你可以使用$provide来创建一个供应商。你需要使用$provide中的provider()方法来定义一个供应商,同时你也可以通过要求$provide被注入到一个应用的config函数中来获得$provide服务。 简单来说: $provide是一个服务,在Auto模块中 这个服务下面有好多方法,是用来定义供应商 而供应商是用来提供服务的,被注入来注入去的东西就是供应商们提供的服务 例子: myMod.config(function($provide) { $provide.provider('greeting', function() { this.$get = function() { return function(name) { alert("Hello, " + name); }; }; }); }); 定义供应商的方法们 AngularJS用$provide去定义一个供应商,这个$provide有5个用来创建供应商的方法: constant value service factory provider decorator (这个有点特殊) Constant 定义常量用的,这货定义的值当然就不能被改变,它可以被注入到任何地方,但是不能被装饰器(decorator)装饰。 var app = angular.module('app', []); app.config(function ($provide) { $provide.constant('movieTitle', 'The Matrix'); }); app.controller('ctrl', function (movieTitle) { expect(movieTitle).toEqual('The Matrix'); }); 语法糖: app.constant('movieTitle', 'The Matrix'); Value 这货可以是string、number甚至function,它和constant的不同之处在于,它可以被修改,不能被注入到config中,但是它可以被decorator装饰。 var app = angular.module('app', []); app.config(function ($provide) { $provide.value('movieTitle', 'The Matrix') }); app.controller('ctrl', function (movieTitle) { expect(movieTitle).toEqual('The Matrix'); }) 语法糖: app.value('movieTitle', 'The Matrix'); Service 它是一个可注入的构造器,在AngularJS中它是单例的,用它在Controller中通信或者共享数据都很合适。 var app = angular.module('app' ,[]); app.config(function ($provide) { $provide.service('movie', function () { this.title = 'The Matrix'; }); }); app.controller('ctrl', function (movie) { expect(movie.title).toEqual('The Matrix'); }); 语法糖: app.service('movie', function () { this.title = 'The Matrix'; }); 在service里面可以不用返回东西,因为AngularJS会调用new关键字来创建对象。但是返回一个自定义对象好像也不会出错。 Factory 它是一个可注入的function,它和service的区别就是:factory是普通function,而service是一个构造器(constructor),这样Angular在调用service时会用new关键字,而调用factory时只是调用普通的function,所以factory可以返回任何东西,而service可以不返回(可查阅new关键字的作用)。 var app = angular.module('app', []); app.config(function ($provide) { $provide.factory('movie', function () { return { title: 'The Matrix' } }); }); app.controller('ctrl', function (movie) { expect(movie.title).toEqual('The Matrix'); }); 语法糖: app.factory('movie', function () { return { title: 'The Matrix' } }); factory可以返回任何东西,它实际上是一个只有$get方法的provider。 示例: angular.module('myApp.services') .factory('User', function($http) { // injectables go here var backendUrl = "http://localhost:3000"; var service = { // our factory definition user: {}, setName: function(newName) { service.user['name'] = newName; }, setEmail: function(newEmail) { service.user['email'] = newEmail; }, save: function() { return $http.post(backendUrl + '/users', { user: service.user }); } }; return service; }); Provider provider是他们的老大,上面的几乎(除了constant)都是provider的封装,provider必须有一个$get方法,当然也可以说provider是一个可配置的factory。 var app = angular.module('app', []); app.provider('movie', function () { var version; return { setVersion: function (value) { version = value; }, $get: function () { return { title: 'The Matrix' + ' ' + version } } } }); app.config(function (movieProvider) { movieProvider.setVersion('Reloaded'); }); app.controller('ctrl', function (movie) { expect(movie.title).toEqual('The Matrix Reloaded'); }); 注意这里config方法注入的是movieProvider,上面定义了一个供应商叫movie,但是注入到config中不能直接写movie,因为前文讲了注入的那个东西就是服务,是供应商提供出来的,而config中又只能注入供应商(两个例外是$provide和$injector),所以用驼峰命名法写成movieProvider,Angular就会帮你注入它的供应商。 Decorator 这个比较特殊,它不是provider,它是用来装饰其他provider的,而前面也说过,他不能装饰Constant,因为实际上Constant不是通过provider()方法创建的。 var app = angular.module('app', []); app.value('movieTitle', 'The Matrix'); app.config(function ($provide) { $provide.decorator('movieTitle', function ($delegate) { return $delegate + ' - starring Keanu Reeves'; }); }); app.controller('myController', function (movieTitle) { expect(movieTitle).toEqual('The Matrix - starring Keanu Reeves'); }); 总结 所有的供应商都只被实例化一次,也就说他们都是单例的 除了constant,所有的供应商都可以被装饰器(decorator)装饰 value就是一个简单的可注入的值 service是一个可注入的构造器 factory是一个可注入的方法 decorator可以修改或封装其他的供应商,当然除了constant provider是一个可配置的factory 个人理解 scope等于什么,html将展现什么,这包括操作的一些交互状态,比如显示隐藏列表,如果scope(其中的判断值)等于false,列表隐藏,相反列表显示。 选择指南 当需要一个简单的可注入值,使用value 当需要在配置阶段访问的值,使用constant 当需要在多个控制器间共享数据和方法,使用service 当需要更灵活的功能,可以返回不同类型的值或函数,使用factory 当需要在配置阶段进行配置,使用provider 当需要修改或扩展现有服务的行为,使用decorator
2017年01月22日
2017-01-16
AngularJS angular.identity 和 angular.noop
AngularJS angular.identity 和 angular.noop angular.identity 函数返回本身的第一个参数。这个函数一般用于函数风格。 格式: angular.identity() 示例代码: (function () { angular.module("Demo", []) .controller("testCtrl", testCtrl); function testCtrl() { var getResult = function (fn, val) { return (fn || angular.identity)(val); }; var result = getResult(function (n) { return n * 2; }, 3); // result = 6 var null_result = getResult(null, 3);// null_result = 3 var undefined_result = getResult(undefined, 3);// undefined_result = 3 }; }()) angular.noop 一个不执行任何操作的空函数。这个函数一般用于函数风格。 格式: angular.noop(); 示例代码: (function () { angular.module("Demo", []) .controller("testCtrl", testCtrl); function testCtrl() { var _console = function (v) { return v * 2; }; var getResult = function (fn, val) { return (fn || angular.noop)(val); }; var firstResult = getResult(_console, 3);//6 var secondResult = getResult(null, 3);//undefined var thirdResult = getResult(undefined, 3);// undefined }; }()) 总结 这两个API的用途有点特殊。总的来说,这两个方法都是用来编写函数时使用的,根据上面示例代码及运行结果可以看出,它们的作用是用来防止函数传入的参数是null或undefined或其他不能操作的对象。 如果不使用这两个函数,当你在函数调用时传入null/undefined/或者其他不能执行的对象,控制台会直接报错。 angular.identity:当传入null/undefined时,返回传入的第二个参数值 angular.noop:当传入null/undefined时,返回undefined
2017年01月16日
1
2
3
4