博文

目前显示的是 七月, 2016的博文

Use HTML5 to resize an image before upload

From: http://stackoverflow.com/questions/23945494/use-html5-to-resize-an-image-before-upload https://github.com/rossturner/HTML5-ImageUploader <input name = "imagefile[]" type = "file" id = "takePictureField" accept = "image/*" onchange = " uploadPhotos ( \' #{ imageUploadUrl } \' ) " /> <form id = "uploadImageForm" enctype = "multipart/form-data" > <input id = "name" value = "#{name}" /> ... a few more inputs ... </form>   window . uploadPhotos = function ( url ){ // Read in file var file = event . target . files [ 0 ]; // Ensure it's an image if ( file . type . match ( /image.*/ )) { console . log ( 'An image has been loaded' ); // Load the image var reader = new FileReader (); reader . onload = function ( readerEvent ) { var image = new Image...

the index position in the original array

1. Using map and indexOf method in an object array var  myArray=[{"id": 1 },{"id":2},{"id":3}]; var pos = myArray.map(function(e) { return e.id; }).indexOf( 1 );// pos === 0 var pos2 = myArray.indexOf({"id":1}); //pos2 always is -1 Ref: http://stackoverflow.com/questions/8668174/indexof-method-in-an-object-array 2. In AngularJS, Using $index OR indexOf( object ) 2.1 indexOf( object ) <div ng-repeat="object in objects">     {{objects.indexOf(person)}} </div> 2.2 using $index value for loops <div ng-repeat="object in objects | filter: {id:20}"> {{$index+1}} <div> Ref:  http://stackoverflow.com/questions/20756694/angularjs-find-the-index-position-of-filtered-value-in-the-original-array

A Practical Guide to AngularJS Directives

From:https://www.sitepoint.com/practical-guide-angularjs-directives-part-two/ Binding Between Isolated and Parent Scope Properties Often, it’s convenient to isolate a directive’s scope, especially if you are manipulating many scope models. But, you may also need to access some parent scope properties inside the directive in order for the code to work. The good news is that Angular gives you enough flexibility to selectively pass parent scope properties to the directive through bindings. Let’s revisit our hello world directive , which changes its background color automatically when somebody types a color name into the text field. Recall that we isolated the scope of the directive and the code stopped working? Well, let’s make it work now! Assume that the variable app is initialized and refers to the Angular module. The directive is shown below. app . directive ( 'helloWorld' , function ( ) { return { scope : { } , restrict : 'AE' , re...

The Top 10 Mistakes AngularJS Developers Make

1 MVC directory structure AngularJS is, for lack of a better term, an MVC framework. The models aren't as clearly defined as a framework like backbone.js, but the architectural pattern still fits well. When working in an MVC framework a common practice is to group files together based on file type: templates / _login . html _feed . html app / app . js controllers / LoginController . js FeedController . js directives / FeedEntryDirective . js services / LoginService . js FeedService . js filters / CapatalizeFilter . js This seems like an obvious layout, especially if coming from a Rails background. However once the app begins to scale, this layout causes many folders to be open at once. Whether using Sublime, Visual Studio, or Vim with Nerd Tree, a lot of time is spent scrolling through the directory tree. Instead of keeping the files grouped by type, group files based on features: ap...