angularjs-directive

Angular ng-repeat groupBy and Keep order

最后都变了- 提交于 2019-12-18 05:37:28
问题 Im using this filter https://github.com/a8m/angular-filter#groupby to order my data like so, and it works great: <div ng-repeat="(key, value) in tags.tags.objects | groupBy:'category.name' "> Now Im trying to keep the order of that groups, by category.order. Is this possible? I tried piping it like so: <div ng-repeat="(key, value) in tags.tags.objects | groupBy:'category.name' | orderBy:'category.order' "> But it does not make any difference 回答1: orderBy filter does not work with objects in

Passing asynchronously obtained data to a directive

假如想象 提交于 2019-12-18 05:10:15
问题 I currently have an AngularJS controller that is basically getting some JSON asynchronously through a $http.get() call, then linking the obtained data to some scope variable. A resumed version of the controller code: mapsControllers.controller('interactionsController', ['$http', function($http) { var ctrlModel = this; $http.get("data/interactionsPages.json"). success(function(data) { ctrlModel.sidebar = {}; ctrlModel.sidebar.pages = data; }). error(function() {...}); }]); Then, I have a

How do I create an AngularJS tooltip directive with a compiled template?

≡放荡痞女 提交于 2019-12-18 04:53:10
问题 I've searched the internet long and hard and found no straight answer. My question is simple, I want to have something like this in my markup: <div my-tooltip-template="'mytt.tpl.html'" my-tooltip-scope="myDataItem">Some text...</div> EDIT: Where myDataItem is a scope variable which contains my data object, and with a template which might look like: <h1>{{dataItem.title}}</h1> <span>{{dataItem.description}}</span> And I want to have that template compiled with the a scope which contains

How do I dynamically define a function to call with ng-click in AngularJS directive template

早过忘川 提交于 2019-12-18 04:46:12
问题 I'm trying to dynamically generate form inputs and an associated action menu based on the model. I'm able to pass the field to be used and the menu, but I can't figure out how to configure ng-click to call the appropriate function defined in the model. See fiddle : http://jsfiddle.net/ahonaker/nkuDW/ HTML: var myApp = angular.module('myApp',[]); myApp.directive('myDirective', function($compile) { return { restrict: "E", replace: true, scope : { field: '=', label: '=', menu: '=' }, link:

Applying ng-class based on value

心不动则不痛 提交于 2019-12-18 04:04:30
问题 I have a simple ng-repeat that displays a list of scores and a value of either Positive or Negative. What i am trying to do is when the value is Negative, display a red background CSS class, and when Positive, display a green CSS class. However, for some reason, i am always seeing the red CSS class on my page. HTML: <tr ng-repeat="scores in Test" ng-class="{true: 'warning', false: 'ok'}[scores.Indicator == 'Negative']"> <td>Overall: {{ scores.Indicator }}</td> </tr> CSS: .warning { background

How can I use Bootstrap Multiselect Dropdown in AngularJS

不问归期 提交于 2019-12-18 03:10:49
问题 I want to use Bootstrap Multiselect Dropdown http://davidstutz.github.io/bootstrap-multiselect/ in AngularJS. I hear that it's necessary to move it to Directive. But I think it's quite complicated & don't know what I have to do. If you have experienced, please guide me! Tks. 回答1: If you don't need to create code that's very re-usable, it's actually not that complicated. The first step is to create a basic directive and to get the DOM element: angular.module('yourapp', []) .directive(

angularjs: force re-rendering/ full refresh a directive template [closed]

安稳与你 提交于 2019-12-18 01:56:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . This is a rewriting because of the off-topic issue: I wrote a directive for a dropdown. I am using the directive two times as kind of a workflow. the first dropdown triggers by change action the refresh of the model of the second one. though the model updates correctly, the view does not. the many times you

Watch controller model value from inside directive

有些话、适合烂在心里 提交于 2019-12-17 23:40:54
问题 I am trying to have angular watch the $viewValue of a controller from inside a directive. fiddle: http://jsfiddle.net/dkrotts/TfTr5/5/ function foo($scope, $timeout) { $scope.bar = "Lorem ipsum"; $timeout(function() { $scope.bar = "Dolor sit amet"; }, 2000); } myApp.directive('myDirective', function() { return { restrict: 'A', require: '?ngModel', link: function (scope, element, attrs, controller) { scope.$watch(controller.$viewValue, function() { console.log("Changed to " + controller.

AngularJS - In a directive that changes the model value, why do I have to call $render?

大兔子大兔子 提交于 2019-12-17 23:34:09
问题 I made a directive designed to be attached to an element using the ngModel directive. If the model's value matches something the value should then set to the previous value. In my example I'm looking for "foo", and setting it back to the previous if that's what's typed in. My unit tests passed fine on this because they're only looking at the model value. However in practice the DOM isn't updated when the "put back" triggers. Our best guess here is that setting old == new prevents a dirty

AngularJS - ng-repeat to assign/generate a new unique ID

∥☆過路亽.° 提交于 2019-12-17 23:24:19
问题 Im using a simple ng-repeat to generate a list of countries. Within each list is a hidden row/div that can be expanded and collapsed. The issue that i am facing, is that before i introduced Angular into my application, i manually hard-coded the element's ID, for example: <li data-show="#country1"> {{country.name}} has population of {{country.population}} <div id="country1"> <p>Expand/collapse content </div> </li> <li data-show="#country2"> {{country.name}} has population of {{country