I have a page in my AngularJS that has an edit button, I need to open the edit page on another tab when I click the edit button. Can it be possible using the angular way? I need to use the same controller to be able to access the data. How can I possible do this? Can someone please give me a sample?
1 Answer
Here's a fiddle to show opening the tab:
https://jsfiddle.net/e8g1m0xs/
I.e.:
angular.module('new_tab', [])
.controller('ExampleController', ['$scope', '$window', function($scope, $window) {
$scope.openTab = function() {
$window.open('https://www.google.com', '_blank');
};
}]);
<div ng-app="new_tab" ng-controller="ExampleController">
<button ng-click="openTab()">New Tab</button>
</div>
But in order to use the same controller for the new tab, and do something like pass information to it, you would have to implement a wildcard pattern into your angular router to pass along state information. I usually do things like that using UI Router. See the section titled URL Parameters.
$windowservice. See the example from the documentation: docs.angularjs.org/api/ng/service/$window