How to implement an ng-change for a custom directive

If you require ngModel you can just call $setViewValue on the ngModelController, which implicitly evaluates ng-change. The fourth parameter to the linking function should be the ngModelCtrl. The following code will make ng-change work for your directive. link : function(scope, element, attrs, ngModelCtrl){ scope.updateModel = function(item) { ngModelCtrl.$setViewValue(item); } } In order for your solution … Read more

How to use `replace` of directive definition?

You are getting confused with transclude: true, which would append the inner content. replace: true means that the content of the directive template will replace the element that the directive is declared on, in this case the <div myd1> tag. http://plnkr.co/edit/k9qSx15fhSZRMwgAIMP4?p=preview For example without replace:true <div myd1><span class=”replaced” myd1=””>directive template1</span></div> and with replace:true <span class=”replaced” … Read more

Understanding the transclude option of directive definition?

Consider a directive called myDirective in an element, and that element is enclosing some other content, let’s say: <div my-directive> <button>some button</button> <a href=”#”>and a link</a> </div> If myDirective is using a template, you’ll see that the content of <div my-directive> will be replaced by your directive template. So having: app.directive(‘myDirective’, function(){ return{ template: ‘<div … Read more

How to create a custom input type?

You can create your own input type=”path” by creating an input directive with custom logic if the type attribute is set to “path”. I’ve created a simple example that simply replaces \ with /. The directive looks like this: module.directive(‘input’, function() { return { restrict: ‘E’, require: ‘ngModel’, link: function (scope, element, attr, ngModel) { … Read more

Illegal use of ngTransclude directive in the template

The reason is when the DOM is finished loading, angular will traverse though the DOM and transform all directives into its template before calling the compile and link function. It means that when you call $compile(clone.children()[0])(scope), the clone.children()[0] which is your <panel> in this case is already transformed by angular. clone.children() already becomes: <div ng-transclude=””>fsafsafasdf</div> … Read more