Angular Directive Different Template

Angular will accept a function as the template option, so you could do something like so: .directive(‘myDirective’, function () { return { templateUrl: function (tElement, tAttrs) { if (tAttrs) { if (tAttrs.type === ‘X’) { return ‘X-template.html’; } if (tAttrs.type === ‘Y’) { return ‘Y-template.html’; } } } } }); For more info, see the … Read more

Understanding AngularJS ng-src

Put the whole path inside the $scope variable. That way ng-src will wait until you provide it with the fully resolved path to the image: <div ng-controller=”MyCtrl”> <img ng-src=”https://stackoverflow.com/questions/18235169/{{ path }}” /> </div> function MyCtrl($scope, $timeout) { var path=”https://si0.twimg.com/profile_images/”; $timeout(function () { $scope.path = path + ‘2149314222/square.png’; }, 1000); }; FIDDLE

angular 2 typescript An implementation cannot be declared in ambient contexts

An implementation cannot be declared in ambient contexts You most probably have your file named as foo.d.ts instead of foo.ts. That marks it as a declaration file (more on that https://basarat.gitbooks.io/typescript/content/docs/types/ambient/d.ts.html) and you cannot put logic in these as you are declaring what logic exists elsewhere.

How to get FormControl instance from ControlValueAccessor

It looks like injector.get(NgControl) is throwing a deprecation warning, so I wanted to chime in with another solution: constructor(public ngControl: NgControl) { ngControl.valueAccessor = this; } The trick is to also remove NG_VALUE_ACCESSOR from the providers array otherwise you get a circular dependency. More information about this is in this talk by Kara Erickson of … Read more

What are the benefits of a directive template function in Angularjs?

The compilation function can be used to change the DOM before the resulting template function is bound to the scope. Consider the following example: <div my-directive></div> You can use the compile function to change the template DOM like this: app.directive(‘myDirective’, function(){ return { // Compile function acts on template DOM // This happens before it … Read more

Is there a way to both check a macro is defined and it equals a certain value at the same time

This may not work for the general case (I don’t think there’s a general solution to what you’re asking for), but for your specific example you might consider changing this sequence of code: #if(DEBUG_PRINT == 1) printf(“%s”, “Testing”); #endif to: if (DEBUG_PRINT == 1) { printf(“%s”, “Testing”); } It’s no more verbose and will fail … Read more

How to use the actual use of ng-Cloak directive in AngularJs?

ng-cloak From the docs: The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display. In brief words, you can use ng-cloak directive … Read more

Angular 2 attribute directive input values are undefined and not set correctly

Input()s aren’t available in the constructor. They are set by change detection, and change detection is run after the component is instantiated. The lifecycle hooks ngOnChanges (every update) and ngOnInit (once after the first ngOnChanges call) are called after change detection updated an input: Change constructor(private el: ElementRef){ this.setElement(); } to constructor(private el: ElementRef) {}; … Read more

AngularJS – Attribute directive input value change

There’s a great example in the AngularJS docs. It’s very well commented and should get you pointed in the right direction. A simple example, maybe more so what you’re looking for is below: jsfiddle HTML <div ng-app=”myDirective” ng-controller=”x”> <input type=”text” ng-model=”test” my-directive> </div> JavaScript angular.module(‘myDirective’, []) .directive(‘myDirective’, function () { return { restrict: ‘A’, link: … Read more

tech