angularjs-scope

AngularJS ng-model value is lost after custom validation directive is triggered

╄→гoц情女王★ 提交于 2019-12-09 17:53:49
问题 I created a custom validation directive and used it in a form. It can be triggered with no problem, but after the validation is triggered, I found that the model value is just lost. Say I have ng-model="project.key" and after validation, project.key doesn't exist in the scope anymore. I think somehow I understood AngularJS wrong and did something wrong. Code speaks. Here is my html page: <div class="container"> ... <div class="form-group" ng-class="{'has-error': form.key.$invalid && form.key.

How can i count the number of errors on Form?

守給你的承諾、 提交于 2019-12-09 16:45:26
问题 FIDDLE How can i count the number of errors made on form ? HTML <div ng-show="form.$submitted && form.$invalid"> Sorry but 3 errors have been made. </div> 回答1: One way you could do this by using the specific count of a specific error criteria, required , pattern etc.. that are available as a part of form's $error[prop] array. In your case you could try using form.$error.required.length :- <div ng-show="form.$submitted && form.$invalid"> Sorry but {{form.$error.required.length}} errors have

AngularJS : Why ng-model value not updating in scope variable

久未见 提交于 2019-12-09 16:43:27
问题 I am using jquery timepicker plugin and its angular directive. When I reset the the scope values from javascript then for the same time scope value not updating. I have tried to make changes on timepicker directive file but not succeeded. Example:- Select start-time 1:00AM then end-time automatically sets to 1:15AM which is updated from watch function in JS file. Now click Reset and values would be deleted or input fields would be blank. Now again select the same time 1:00AM the end-time is

Reacting on angular events in a directive without injecting $rootScope

两盒软妹~` 提交于 2019-12-09 16:01:59
问题 I wonder if you have an example of a directive code that reacts on angular events like $routeChangeError without injecting $rootScope in to it (to use $on in link function). It breaks in my opinion MV* pattern and "produces" smell-code (gives the possibility to manipulate root scope in a directive). Thanks in advance. 回答1: If you are only listening for events, you don't have to use the $rootScope ; do e.g. $scope.$on("$routeChangeError") on the scope of the directive, from either controller

angular - ng-if - how to callback after ng-if template has been rendered

旧城冷巷雨未停 提交于 2019-12-09 14:18:36
问题 in Angular, I need to call a function after an element with certain class has been loaded. Display of the element is controlled via ng-if='expr'. Value of $scope.expr is set after some ajax call has responded. Now, if I try putting $watch on expr, or using $evalAsync. it is not working. probably the reason being that these events are run before the template part actually runs. Here is a sample code : http://jsbin.com/kuyas/1/edit Here I need a callback sort of thing on ng-if that gets

Why does ng-style not work on the same element as a custom directive?

。_饼干妹妹 提交于 2019-12-09 14:14:21
问题 I'm trying to apply the ng-style attribute on a custom directive tag, kind of like so: <my-directive ng-style="myStyle"></my-directive> Inside the controller I have: $scope.myStyle = { "background": "red" } This doesn't seem to work though. When I inspect the HTML 'MyStyle' does not get rendered. When I apply the same ng-style tag on a regular div it does render properly. Why doesn't ng-style work on custom directive tags? 回答1: Your directive likely defines an isolate scope: scope: { ... } .

How to bind boolean values in angular directives?

故事扮演 提交于 2019-12-09 14:00:34
问题 I'd like to bind/set some boolean attributes to a directive. But I really don't know how to do this and to achieve the following behaviour. Imagine that I want to set a flag to a structure, let's say that a list is collapsable or not. I have the following HTML code: <list items="list.items" name="My list" collapsable="true"></list> items are two-way binded, name is just an attribute I'd like that collapsable attribute to be available in the list's $scope either by passing a value (true, false

Access $state inside template

不打扰是莪最后的温柔 提交于 2019-12-09 11:03:23
问题 Background I create an app with a menu on the left which contains several menu items. When the user clicks on an item (or access it via an URL), I want to highlight the item (i.e. apply the class 'active' on the corresponding <li> ). Note : I handle routes with ui.router . What I tried Up to now, I try to use a ng-class directive : <div class="col-sm-3 col-md-2 sidebar"> <ul class="nav nav-sidebar"> <li ng-class="{active: current=='container.item1'}"> <a href="#/a/item1">Item 1</a> </li> <li

Sharing data between AngularJS controllers? [duplicate]

随声附和 提交于 2019-12-09 09:43:22
问题 This question already has answers here : Can one AngularJS controller call another? (13 answers) Closed 6 years ago . How do I store the items I've selected in a checkbox with other controllers? My attempt (see the plnkr for views): script.js (controllers) var myApp = angular.module('myApp', []); myApp.factory('CooSelection', function () { return {selectedCoo: []} }) function CooListCtrl($scope, CooSelection) { $scope.coos = {"Coos": ["spark", "nark", "hark", "quark"]}; $scope.coo_list

How ngRepeat works in angularjs?

混江龙づ霸主 提交于 2019-12-09 07:13:06
问题 I'm preparing a presentation for a talk so I drew a diagram on how ngRepeat works. The focus of the talk is ngRepeats role in performance pitfalls but I'm not sure if everything is right in the diagram or if I missed something. Are there more loops in ngRepeat that could affect the performance, how does a change in the filter with a model affect the reevaluation of the ngRepeat(does it just trigger the watch the same way as the model/array change ?) 来源: https://stackoverflow.com/questions