angularjs-directive

AngularJS Scopes and Deferreds

人盡茶涼 提交于 2019-12-11 02:05:41
问题 I have a service that does something hard and returns a promise: .factory('myService', function($q) { return { doSomethingHard: function() { var deferred = $q.defer(); setTimeout(function() { deferred.resolve("I'm done!"); }, 1000); return deferred.promise; } }; }) I have a controller that adds a function to the scope using that service: .controller('MyCtrl', function($scope, myService) { $scope.doSomething = function() { var promise = myService.doSomethingHard(); promise.then(function(result

AngularJS do link function after $http response returned

喜你入骨 提交于 2019-12-11 01:54:19
问题 I need to perform a link function in a directive after an http response returns. The idea is something like this: <input type="text" my-field> <script> angular.module("mine") .controller ('myCtrl', function ($scope) { $http.get("/my/service").success(function (data, status, headers, config) { // OK, done with the query... now I know my field name to bind to. Somehow // I have to get it down to the link function below... }); }) .directive ('myField', function ($compile) { return { link:

AngularJS v1.2.x $digest() infinite loop Directive isolated scope object param

。_饼干妹妹 提交于 2019-12-11 01:38:35
问题 Simplified version of problem, view web dev console: http://plnkr.co/edit/3wKmWz?p=preview Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: So why does passing an object into a directive with an isolated scope cause an infinite $digest() loop? // controller // AngularJS 1.2.x infinite digest caused when returning object into directive $scope.ctrlObjReturnFn = function() { return {test:true}; } // view <div test-dir

AngularJS templateUrl vs template - isolate scope

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:28:52
问题 I have the following directive: offerListSorters.directive('offersSorter', ['myState', '$templateCache', function (myState, $templateCache){ return { scope: {}, controller: function($scope, $element, $attrs, $transclude) { [...] }, restrict: 'E', //templateUrl: 'partials/offersSorterDirective.html', template: $templateCache.get('partials/offersSorterDirective.html'), replace: true, transclude: true }; }]); And I use Karma + Jasmine to test this code and it works. But now if I switch to the

AngularJS: Returning a promise in directive template function

霸气de小男生 提交于 2019-12-11 01:26:56
问题 As the title already says, I'd like to return a promise in the directive template function i.e.: angular.module('someModule', []) //... .directive('someDirective', function() { return { //... restrict: 'E', template: function() { var deferred = $q.defer(); //Some Async function which will call deferred.resolve return deferred.promise; //Promise not supported by template property } }; }); Since the template property doesn't support this, is there any (simple) way to "emulate" that? It looks

Difference between $http.get , $http.post ,$http.put , $http.delete $http.head and $http.jsonp [closed]

非 Y 不嫁゛ 提交于 2019-12-11 01:25:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am new to angular js and web development. Please help me. Today i read about $http in angular js but i am only aware about the get and post methods . Can Please anyone explain ,me what is the Difference between $http.get , $http.post ,$http.put , $http.delete $http.head and

Prevent angularjs animation from running on element that is initially hidden when loaded [duplicate]

与世无争的帅哥 提交于 2019-12-11 01:22:10
问题 This question already has answers here : ngAnimate on ngShow. Preventing animation when it starts first time (4 answers) Closed 4 years ago . http://codepen.io/cflynn07/pen/hbgxf ^ Example I have an angularjs animation, and I don't want it to run on page load for an element that is supposed to be hidden. Right now, the element is shown, then the slide up animation occurs and hides the element. 回答1: Is this something you're looking for? http://codepen.io/anon/pen/JaHKL Basically you need set

AngularJS + Coffeescript - 'Hello World' directive not working

浪尽此生 提交于 2019-12-11 01:05:37
问题 I can't make the simplest of directives work in my AngularJS + Coffeescript project. I have this code in directives.coffee: 'use strict' app_name = "myApp" app = angular.module "#{app_name}.directives", [] # Directive to include the version number of my project app.directive 'appVersion', [ 'version', (version) -> (scope, element, attrs) -> element.text version ] # Hello world directive app.directive 'hello', () -> restict: 'E' template: '<div>Hello World</div>' And in my template, when I do

Does UWP app support ajax?

末鹿安然 提交于 2019-12-11 00:57:36
问题 I have a windows 8 hybrid app and now I want to migrate it to UWP. I am facing two issues and I have been searching on the internet for quite a few time. I want to know if UWP support ajax function. Also my anchor tag in href is not parsing. What might be the reason. 回答1: I want to know if UWP support ajax function The answer is yes, you can use ajax in UWP Application. But there are a few things you need to notice when using ajax in UWP. If you are using ajax to get data from a remote server

how to test $http call in angular js?

一个人想着一个人 提交于 2019-12-11 00:53:57
问题 I am trying to test my $http request using karma and jasmine.I make one controller and inject a service .In service I call $http service.I need to test that service how I will test this service this is my controller. angular.module('app',[]).controller('first',function($scope,data){ $scope.name='test'; data.getData().then(function(data){ console.log(data); }) }).factory('data',function($http){ return{ getData:getData } function getData(){ return $http.get('data.json').success(successCall)