- Support for delaying the lookup (good for preventing too many AJAX requests)
- Some fixes regarding the data fed to the onselect callback
For the proper source, and other examples, please see the original gist and the extended version
myApp.directive('ngFocus', function( $timeout ) { | |
return function( scope, elem, attrs ) { | |
scope.$watch(attrs.ngFocus, function( newval ) { | |
if ( newval ) { | |
$timeout(function() { | |
elem[0].focus(); | |
}, 0, false); | |
} | |
}); | |
}; |
var watcher = $scope.$watch('data.counter', function(newValue, oldValue) { | |
iElement.css('width', 50 * newValue + 'px'); | |
if (newValue >= 10) { | |
// when data.counter reaches 10, destruct the watcher. | |
watcher(); | |
} | |
}); |
<h1>Bye {{code}}</h1> |
var myApp = angular.module('myApp', []); | |
//service style, probably the simplest one | |
myApp.service('helloWorldFromService', function() { | |
this.sayHello = function() { | |
return "Hello, World!" | |
}; | |
}); | |
//factory style, more involved but more sophisticated |
/** | |
* Usage: | |
* {{some_text | cut:true:100:' ...'}} | |
* Options: | |
* - wordwise (boolean) - if true, cut only by words bounds, | |
* - max (integer) - max length of the text, cut to this number of chars, | |
* - tail (string, default: ' …') - add this string to the input | |
* string if the string was cut. | |
*/ | |
angular.module('ng').filter('cut', function () { |
$scope.$on('$includeContentLoaded', function(event) { | |
console.log('another include was loaded', event.targetScope); | |
}); |
myApp.directive('markdown', function () { | |
var converter = new Showdown.converter(); | |
return { | |
restrict: 'AE', | |
link: function (scope, element, attrs) { | |
if (attrs.markdown) { | |
scope.$watch(attrs.markdown, function (newVal) { | |
var html = converter.makeHtml(newVal); | |
element.html(html); | |
}); |
For the proper source, and other examples, please see the original gist and the extended version
window.onload = function () { | |
var objDiv = document.getElementById("idOfYourDiv"); | |
objDiv.scrollTop = objDiv.scrollHeight; | |
} |