Passing current scope to an AngularJS Service

To let the controller know when something async happens, use Angular promises. To provoke the $apply, you don’t need the scope, you can call $rootScope.$apply, as there is no difference calling it in a specific scope or in the root. Regarding the variable reading, it would be better if you received parameters. But you could … Read more

AngularJS : Differences among = & @ in directive scope? [duplicate]

This can be confusing but hopefully a simple example will clarify it. First, let’s separate model bindings from behaviors. Here is a fiddle that should help tie things together: http://jsfiddle.net/jeremylikness/3pvte/ And explained … if your directive looks like this: <my-directive target=”foo”/> Then you have these possibilities for scope: { target : ‘=’ } This will … Read more

Update parent scope variable in AngularJS

You need to use an object (not a primitive) in the parent scope and then you will be able to update it directly from the child scope Parent: app.controller(‘ctrlParent’,function($scope){ $scope.parentprimitive = “someprimitive”; $scope.parentobj = {}; $scope.parentobj.parentproperty = “someproperty”; }); Child: app.controller(‘ctrlChild’,function($scope){ $scope.parentprimitive = “this will NOT modify the parent”; //new child scope variable $scope.parentobj.parentproperty = … Read more

Get value when selected ng-option changes

as Artyom said you need to use ngChange and pass ngModel object as argument to your ngChange function Example: <div ng-app=”App” > <div ng-controller=”ctrl”> <select ng-model=”blisterPackTemplateSelected” ng-change=”changedValue(blisterPackTemplateSelected)” data-ng-options=”blisterPackTemplate as blisterPackTemplate.name for blisterPackTemplate in blisterPackTemplates”> <option value=””>Select Account</option> </select> {{itemList}} </div> </div> js: function ctrl($scope) { $scope.itemList = []; $scope.blisterPackTemplates = [{id:1,name:”a”},{id:2,name:”b”},{id:3,name:”c”}]; $scope.changedValue = function(item) { … Read more

Controller not a function, got undefined, while defining controllers globally

With Angular 1.3+ you can no longer use global controller declaration on the global scope (Without explicit registration). You would need to register the controller using module.controller syntax. Example:- angular.module(‘app’, []) .controller(‘ContactController’, [‘$scope’, function ContactController($scope) { $scope.contacts = [“abcd@gmail.com”, “abcd@yahoo.co.in”]; $scope.add = function() { $scope.contacts.push($scope.newcontact); $scope.newcontact = “”; }; }]); or function ContactController($scope) { $scope.contacts … Read more

AngularJs: Reload page

You can use the reload method of the $route service. Inject $route in your controller and then create a method reloadRoute on your $scope. $scope.reloadRoute = function() { $route.reload(); } Then you can use it on the link like this: <a ng-click=”reloadRoute()” class=”navbar-brand” title=”home” data-translate>PORTAL_NAME</a> This method will cause the current route to reload. If … Read more

Angularjs: ‘controller as syntax’ and $watch

Just bind the relevant context. $scope.$watch(angular.bind(this, function () { return this.name; }), function (newVal) { console.log(‘Name changed to ‘ + newVal); }); Example: http://jsbin.com/yinadoce/1/edit UPDATE: Bogdan Gersak’s answer is actually kind of equivalent, both answers try binding this with the right context. However, I found his answer cleaner. Having that said, first and foremost, you … Read more

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