When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.
-
Raw Attribute Strings
<div my-directive="some string" another-param="another string"></div>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Flyweight.js - Copyright Addy Osmani, 2012. | |
// Consider public domain | |
// My implementation in JS of this: | |
// http://en.wikipedia.org/wiki/Flyweight_pattern | |
// Simulate pure virtual inheritance/'implement' keyword for JS | |
Function.prototype.implementsFor = function (parentClassOrObject) { | |
if (parentClassOrObject.constructor == Function) { | |
// Normal Inheritance | |
this.prototype = new parentClassOrObject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chopStyle2Num = style => Number(style.substr(0, style.length - 2)); | |
const closestParent = (element, tagName) => { | |
let parentNode = element.parentNode; | |
while (parentNode.nodeName.toLowerCase() !== tagName) { | |
parentNode = parentNode.parentNode; | |
if (parentNode === document.body) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fire an event handler to the specified node. Event handlers can detect that the event was fired programatically | |
* by testing for a 'synthetic=true' property on the event object | |
* @param {HTMLNode} node The node to fire the event handler on. | |
* @param {String} eventName The name of the event without the "on" (e.g., "focus") | |
*/ | |
function fireEvent(node, eventName) { | |
// Make sure we use the ownerDocument from the provided node to avoid cross-window problems | |
var doc; | |
if (node.ownerDocument) { |
当单独使用 transformResponse 时: 如下,当然不推荐这样做, 最好是参考官方例子,将自己的 transformResponse 作为默认 transformResponse 的数组的一个成员,自己参见官网
export const MenuResource = genResource('/menus', null, null, {
query: {
isArray: true,
method: 'GET',
transformResponse: (result) => {
const res = angular.fromJson(result);
return res;
//::LICENSE:://
(function(global){
//::SIGNAL_BINDING_JS:://
//::SIGNAL_JS:://
//exports to multiple environments
if(typeof define === 'function' && define.amd){ //AMD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
function mixParams(url, params) { | |
let copyParams = Object.assign({}, params); | |
let urls = url.replace(/\:([^/:?&]+)/g, ($0, $1) => { | |
delete copyParams[$1]; | |
return params[$1]; | |
}); | |
urls.includes('?') ? urls = urls + '&' : urls = urls + '?'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Service from 'path/to/service'; | |
import 'jasmine-ajax' | |
describe('Service', () => { | |
let request, promise; | |
let instance = Service; | |
let payload = {foo:'bar'}; | |
let path = '/path'; | |
let callback = jasmine.createSpy('callback'); |