Get DOM element by scope $id

Although it’s not very sexy each dom node gets a class ng-scope so you could tech do something like this maybe: function getScope(id) { var elem; $(‘.ng-scope’).each(function(){ var s = angular.element(this).scope(), sid = s.$id; if(sid == id) { elem = this; return false; // stop looking at the rest } }); return elem; }

Can I trigger a form submit from a controller?

You can add submit method to a FormController. I did so: <form ng-form-commit action=”https://stackoverflow.com/” name=”payForm” method=”post” target=”_top”> <input type=”hidden” name=”currency_code” value=”USD”> <button type=”button” ng-click=’save(payForm)’>buy</button> </form> .directive(“ngFormCommit”, [function(){ return { require:”form”, link: function($scope, $el, $attr, $form) { $form.commit = function() { $el[0].submit(); }; } }; }]) .controller(“AwesomeCtrl”, [“$scope”, function($scope){ $scope.save = function($form) { if ($form.$valid) { … Read more

AngularJS: Access directive’s isolated scope from parent controller

To maintain proper separation of concerns, you should not mix scopes. Not to mention that it will be hard to synchronize. To summarize: your directive should not know anything about the parent scope (or its controller) and your controller should not know anything about a directive’s internals. They are separate components in separate layers. The … Read more

Angular “Unknown Provider” error after minification with Grunt Build in Yeoman app

It sounds like the common issue of Angular’s reliance on the name of arguments for dependency injection. Make sure when you pass dependencies that you include the dependency names as strings so that Angular will know what to inject after minification (since string values won’t be changed in the minification process). myApp.controller(‘myCtrl’, [‘$scope’, ‘$http’, function($scope, … Read more

Angularjs how to upload multipart form data and a file?

First of all You don’t need any special changes in the structure. I mean: html input tags. <input accept=”image/*” name=”file” ng-value=”fileToUpload” value=”{{fileToUpload}}” file-model=”fileToUpload” set-file-data=”fileToUpload = value;” type=”file” id=”my_file” /> 1.2 create own directive, .directive(“fileModel”,function() { return { restrict: ‘EA’, scope: { setFileData: “&” }, link: function(scope, ele, attrs) { ele.on(‘change’, function() { scope.$apply(function() { var … Read more

Can I access parameters in my protractor configuration file?

I am not completely sure if protractor globals are set at the beforeLaunch() stage, but they are definitely available at onPrepare() step. Access the params object through the global browser object: console.log(browser.params.baseUrl); Update: Using Jasmine 2.6+, protractor 4.x, browser.params was empty, but the following worked in onPrepare() step: console.log(browser.baseUrl);

Add ng-click dynamically in directive link function

Better Solution (New): After reading through the Angular docs I came across this: You can specify template as a string representing the template or as a function which takes two arguments tElement and tAttrs (described in the compile function api below) and returns a string value representing the template. So my new directive looks like … Read more

How can I send request again in response interceptor?

Here is my solution using promises for those interested. Basically you need to request a new session, and wait for the response before sending a new request corresponding to the original request (using response.config). By returning the promise $http(response.config) you ensure that the response will be treated as if it was the original request. (syntax … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)