How to call a function from another controller in AngularJS? [duplicate]

Communication between controllers is done though $emit + $on / $broadcast + $on methods. So in your case you want to call a method of Controller “One” inside Controller “Two”, the correct way to do this is: app.controller(‘One’, [‘$scope’, ‘$rootScope’ function($scope) { $rootScope.$on(“CallParentMethod”, function(){ $scope.parentmethod(); }); $scope.parentmethod = function() { // task } } ]); … Read more

Simple ng-include not working

You’re doing an include of header.url instead of header.html. It looks like you want to use literals in the src attribute, so you should wrap them in quotes, as was mentioned in the comments by @DRiFTy. Change <div ng-include src=”https://stackoverflow.com/questions/22991658/partials/structure/header.url”></div> <div ng-include src=”partials/structure/navigation.url”></div> <div id=”view” ng-view></div> <div ng-include src=”partials/structure/footer.url”></div> to <div ng-include src=”‘partials/structure/header.html'”></div> <div ng-include … Read more

How do I share $scope data between states in angularjs ui-router?

I created working plunker, showing how to use $scope and UI-Router. The state definition is unchanged: $stateProvider // States .state(“main”, { controller:’mainController’, url:”/main”, templateUrl: “main_init.html” }) .state(“main.1″, { controller:’mainController’, parent: ‘main’, url:”/1”, templateUrl: ‘form_1.html’ }) .state(“main.2”, { controller:’mainController’, parent: ‘main’, url: “/2”, templateUrl: ‘form_2.html’ }) But each state can have different controller. Why? because each … Read more

AngularJS 1.5+ Components do not support Watchers, what is the work around?

Writing Components without Watchers This answer outlines five techniques to use to write AngularJS 1.5 components without using watchers. Use the ng-change Directive Use the $onChanges Life-cycle Hook Use the $doCheck Life-cycle Hook Intercomponent Communication with require Push Values from a Service with RxJS Use the ng-change Directive what alt methods available to observe obj … Read more

Scope issues with Angular UI modal

When nested scopes are involved, do not bind <input>s directly to members of the scope: <input ng-model=”name” /> <!– NO –> Bind them to at least a level deeper: <input ng-model=”form.name” /> <!– YES –> The reason is that scopes prototypically inherit their parent scope. So when setting 1st level members, these are set directly … Read more

AngularJS – How can I create a new, isolated scope programmatically?

You can create a new scope manually. You can create a new scope from $rootScope if you inject it, or just from your controller scope – this shouldn’t matter as you’ll be making it isolated. var alertScope = $scope.$new(true); alertScope.title=”Hello”; AlertFactory.open(alertScope); The key here is passing true to $new, which accepts one parameter for isolate, … Read more

Confirmation dialog on ng-click – AngularJS

If you don’t mind not using ng-click, it works OK. You can just rename it to something else and still read the attribute, while avoiding the click handler being triggered twice problem there is at the moment. http://plnkr.co/edit/YWr6o2?p=preview I think the problem is terminal instructs other directives not to run. Data-binding with {{ }} is … Read more