angularjs-directive

Why ngModel's $render is not called when the model changes in AngularJS?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 15:59:57
问题 DEMO Why in the following example $render is not called when the button is clicked? <input type="text" ng-model="client.phoneNumber" phone-number> <button ng-click="client.phoneNumber='1111111111'">Change phone number</button> .directive("phoneNumber", function() { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attrs, ngModel) { ngModel.$render = function() { alert('rendering'); // This is not called }; } }; }); 回答1: The input directive is running after your

$locationChangeSuccess triggers four times

对着背影说爱祢 提交于 2019-12-04 15:55:19
I am new to angular Js. My application flow is as below: 1) I have a view controller wherein, each view controller sets the breadcrumb data with the help of Breadcrumbs factory. 2) Breadcrumbs factory takes data from view controller and attaches data to $location.$$state object.(reason for storing in state object is if back button is pressed, view controller doesn't instantiate so I can refer history data for breadcrumbs ) below is code to attach data to state object: var state = $location.state(); state.breadcrumb = breadcrumbData; $location.replace().state(state); 3) I have also created

Angular JS - How can i animate on model change?

独自空忆成欢 提交于 2019-12-04 15:47:24
问题 i'm trying to do a nice fadeout+fadein transition when the currentVertical changes. in knockout it was so simple but i can't figure it out here. please help. the following code displays a UL list which is "bound" to a pricings array in the $scope.currentVertical when an LI element is clicked, the $scope.currentVertical is changed and the UL list updates accordingly. This works fine, but i would like the entire #container div to fade out and fadein when $scope.currentVertical is changed.

AngularJS Directive is not linking when using an input in the template to replace an input in the html with the type attribute specified

大兔子大兔子 提交于 2019-12-04 14:56:34
I'm having a really specific, strange issue. We have to code our app to support IE8. We are wrapping the Angular-Bootstrap's Typeahead directive in a template to encapsulate a lookup widget with some extra functionality. The issue we're having is that our directive template looks like this: '<input ng-model="typeaheadValue" typeahead="xxx.code as formatXxx(xxx) for xxx in searchXxxs($viewValue)">' Inside the link function in the directive we are simply calling replace: true and passing in some values to the scope. This works beautifully in both IE8 and Chrome. Now, the REALLY strange part is

Can I require generic parent directive in AngularJS

社会主义新天地 提交于 2019-12-04 14:36:14
Can a child directive require a parent without knowing exactly which directive that parent is, just that it "implements an interface"? For example: <parentImplX> <child></child> </parentImplX> In the above example I want the controller injected into child to be ParentImplXCtrl . But If I do: <parentImplY> <child></child> </parentImplY> I want the controller to be ParentImplYCtrl . directives.directive("parentImplX", function () { return { scope: {}, restrict: "E", controller: ParentImplXCtrl } }); directives.directive("parentImplY", function () { return { scope: {}, restrict: "E", controller:

ng-app V/S data-ng-app in AngularJS

非 Y 不嫁゛ 提交于 2019-12-04 14:34:04
In AngularJS when using ng-app : ng-app found in the document will be used to define the root element to auto-bootstrap as an application. In some of the application it is being used as data-ng-app . Is there any difference in both of the following declaration, If Yes what & If No then which one is significant and why ? 1. <body ng-app> <p>{{ 1 + 2 }}</p> </body> 2. <body data-ng-app> <p>{{ 1 + 2 }}</p> </body> Both and are the same except for the fact that if you want your template/code to be according to be HTML compliant and follow the best practices. Use data-ng-app. This is what the

jQuery slider not working in angularjs

纵然是瞬间 提交于 2019-12-04 14:24:08
问题 My slider wont come up on first time navigation of the page. However when I hard refresh the page then it comes up and also if I replace the <div ng-view></div> code with the front.html page content then also the slider starts working. Let me know what I am doing wrong in angular as I believe it is something basic that I am missing. Following is my layout code - <!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="utf-8" /> <title>WEBSITE</title> <link rel="stylesheet" href="assets/css

How can I generate on the fly directives in AngularJS?

♀尐吖头ヾ 提交于 2019-12-04 14:03:33
I want to be able to take an array of strings, and then create directives based upon those strings. Either element or attribute will work fine but can't seem to get it working. <div ng-repeat="module in modules.directives"> <div {{module.directive}}></div> </div> <div ng-repeat="module in modules.directives"> <{{module.directive}}></{{module.directive}}> </div> <div ng-repeat="module in modules.directives"> <{{module.directive}} /> </div> Can't get any of these to work. Any ideas? You could define a directive that would proxy another directive like so <div proxy="'ng-if'" proxy-value="'foo'"><

Double indirection in data-binding. Interpolate string in a template

元气小坏坏 提交于 2019-12-04 13:30:48
I'm trying to resolve double binding in the link function of a directive: scope.a = "surprise"; scope.b = "{{ a }}"; the template is <div>{{ b }}</div> it's rendered like <div>{{ a }}</div> is it possible to get the view to display <div>surprise</div> ? I've been trying to recompile the directive, but once b is binded, contents are a string and angularJS won't attempt any more to bind them. One way is to interpolate on function rather then value directly function test($scope) { $scope.a = "surprise"; $scope.b = function () { return $scope.a; }; } <div>{{ b() }}</div> Eduard Gamonal The

What is the main use of transclusion in angularjs

岁酱吖の 提交于 2019-12-04 13:10:19
I have recently come across transclusion in directives, what is the purpose of having this concept. As far as I know its encapsulation of an object and have 2-way binding possibly. But this can be possible by using '=' in the scope attribute in directive. So whats the big deal about directive? Transclude allows : To create directives that wrap other elements. To clone the same transcluded contents multiple times. To re-clone the trancluded contents when an event occurs. ngTransclude and $transclude When using the transclude option, the element contents are being removed from the DOM during the