- 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
app.directive("clickToEdit", function() { | |
var editorTemplate = '<div class="click-to-edit">' + | |
'<div ng-hide="view.editorEnabled">' + | |
'{{value}} ' + | |
'<a ng-click="enableEditor()">Edit</a>' + | |
'</div>' + | |
'<div ng-show="view.editorEnabled">' + | |
'<input ng-model="view.editableValue">' + | |
'<a href="#" ng-click="save()">Save</a>' + | |
' or ' + |
window.onload = function () { | |
var objDiv = document.getElementById("idOfYourDiv"); | |
objDiv.scrollTop = objDiv.scrollHeight; | |
} |
For the proper source, and other examples, please see the original gist and the extended version
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); | |
}); |
$scope.$on('$includeContentLoaded', function(event) { | |
console.log('another include was loaded', event.targetScope); | |
}); |
/** | |
* 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 () { |
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 |
<h1>Bye {{code}}</h1> |
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(); | |
} | |
}); |