angularjs-directive

Get value from directive to $scope in controller

假装没事ソ 提交于 2019-12-07 21:38:29
问题 In my Directive, I've getting some data from my backend like this: var monster_info = angular.element(this).find("img").attr("title"); $http.get("lib/terrain.php", {params: { monster_data:monster_info}}).success(function(data) { console.log(data); }); I want this data to appear at my site, so I've tried to declare a variable like this in my controller: $scope.fish = []; Then I just assign the data value like this in my directive: $scope.fish = data; But nothing is printed out. How does the

ng-repeat and ng-switch doesn't work on same element

佐手、 提交于 2019-12-07 19:23:03
问题 JS $scope.mode = "test" $scope.array = ['test1', 'test2', 'test3'] HTML <div ng-switch on="mode"> <div ng-repeat="item in array" ng-switch-when="test"> Test {{item}} </div> </div> When I do this the above, the output I get is Test Test Test It can't seem to access item. If I remove the ng-switch-when then it works fine. 回答1: It is because ng-switch creates a child scope and same applies for ng-repeat. ng-repeat runs at priority 1000 and ng-switch at 800 . So the child scope created by ng

AngularJS multiple directives on same element, $compile:multidir ERROR

两盒软妹~` 提交于 2019-12-07 19:05:56
问题 Here is the plunkr: http://plnkr.co/edit/CzcVzKSvpKJTuTKARVJz?p=preview and this is my simple code: .directive('ngB', [function () { return { 'restrict': 'A', 'scope': { 'ngB': '=' }, 'link': function($scope, el) { var clss = 'b' , go = function () { if ($scope.ngB) { el.removeClass('a'); el.addClass(clss); } else { el.removeClass(clss); } }; $scope.$watch('ngB', function () { go(); }); } }; }]) .directive('ngF', [function () { return { 'restrict': 'A', 'scope': { 'ngF': '=' }, 'link':

Angular js - On scroll up load more data

橙三吉。 提交于 2019-12-07 19:04:44
问题 I have developed a chatting system like Facebook. Now I want to do load earlier messages. Can anyone help me to do the functionality like when I scroll up it should load earlier messages same like Facebook. 回答1: You may want to take a look at ngInfiniteScroll. With this module, it is very easy to implement what you want. Here is an example: <div ng-app='myApp' ng-controller='DemoController'> <div infinite-scroll='loadMore()' infinite-scroll-distance='2'> <img ng-repeat='image in images' ng

Get ng-repeat complete in angular directive

二次信任 提交于 2019-12-07 17:26:41
问题 In the code below, how does the angular directive 'myscroll' know what ng-repeat elements are being created? <myscroll> <div ng-repeat="a in arr">{{a}}</div> </myscroll> I know that the $last event is not fired to the parent directive, how can I solve this? myapp.directive("myscroll", function () { return{ restrict: "E", transclude: true, template: "<span class='left'></span><div class='mask' ng-transclude></div><span class='right'></span>", link: function (scope, element, attr) { scope.

Improve AngularJS directive code

旧街凉风 提交于 2019-12-07 16:41:08
问题 I wrote an AngularJS directive, but I'm pretty new about it, and I don't know if I done in the "Angular way"... Here is my plunker with the code: http://plnkr.co/edit/X1tOk4z8f6dCK3mfB7HP?p=preview html: <!DOCTYPE html> <html ng-app="app"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <meta charset=utf-8 /> <title>Directive Test</title> <script src="script.js"></script> </head> <body ng-controller="MainCtrl"> <button id="button1" ng-click=

Angular two-way-binding with sub elements

折月煮酒 提交于 2019-12-07 16:31:28
问题 my problem is with creating an angular directive. I want to create a group of checkboxes with just one single ng-model. It's like a bitfield or flags, i.e. the checkboxes have values from 0, 1, 2, 3 up to n but for ng-model I just want to add 2^value of all checked checkboxes. The values to add are then 1, 2, 4, 8, 16, ... I wonder if there is a better, more correct or just simpler solution to my problem. http://plnkr.co/edit/9h7EkEpDohXTniIDHdc5 In the example you can change the value in the

“Uploader” must be an instance of FileUploader

大兔子大兔子 提交于 2019-12-07 16:25:00
问题 I referred this: https://github.com/nervgh/angular-file-upload/tree/version-3.0.0-alpha angular.min.js:14540 TypeError: "Uploader" must be an instance of FileUploader at link (http://localhost:8080/services/angular-file-upload.js:1874:24) at invokeLinkFn (http://localhost:8080/lib/js/angular.min.js:10445:8) at nodeLinkFn (http://localhost:8080/lib/js/angular.min.js:9733:9) at compositeLinkFn (http://localhost:8080/lib/js/angular.min.js:8712:10) at compositeLinkFn (http://localhost:8080/lib/js

How to insert $compile'd HTML code inside the directive without getting $digest recursion error?

风格不统一 提交于 2019-12-07 15:20:37
问题 I have a directive that, depending on the ng-repeat item data (from the database), build custom HTML with a switch case: app.directive('steps', function($compile){ return { 'restrict': 'A', 'template': '<h3>{{step.name}}</h3><ul ng-repeat="opt in step.opts"><div ng-bind-html-unsafe="extra(opt)"></div></ul>', 'link': function($scope, $element){ $scope.extra = function(opt){ switch ($scope.step.id){ case 1: return "<div>Some extra information<select>...</select></div>" case 2: return "<div>

How to invoke ng-click from a directive partial?

孤街醉人 提交于 2019-12-07 15:08:56
问题 I have a directive that has a local scope where a partial contains ng-click. The Fiddle is there: http://jsfiddle.net/stephanedeluca/QRZFs/13/ Unfortunatelly, since I moved my code to the directive, ng-click does not fire anymore. The controller and the directive is as follows: var app = angular.module('myApp', ['ngSanitize']); app.directive('plantStages', function ($compile) { return { restrict: 'E', transclude: true, template: '<figure class="cornStages">\ <p ng-transclude style="color: