1

I am developing system using angularjs with codeigniter. What I want to do:

  • There is anchor tag [edit] for every user (user list is shown using ng-repeat) on click of edit i want to open new window.Opening new window is not an issue. I want to pass user_id to that new widow. So issue is: passing user_id.
  • When I go to new window, after edit-update done, (edit update is not an issue), I want to refresh the current application (previous widow:from where I switched).

Hope you got my issue(s).

Sample Code:

<div ng-repeat="user in allUsers">
Only displaying : {{user.user_id}}, It is OK.
<a title="Edit in new window" href='javascript:window.open(\"".base_url()."phpcontroller/loadingview/user_id \",\"User Edit\", \"width=\"+screen.width+\",height=\"+screen.height+\",fullscreen=yes,location=no\");'  >Test edit</a>
</div>
  • This HTML/php PAGE is loaded through angularjs. So it is partial, thats why I cant use php functionality(eg. base_url(), php variable) here. How can I give basepath in partial. Is there any way to declare base url globally in app.js or controllers.js, so that I can use it in partials?

Please try to give suggestions, solutions. If you not get my issues clearly, please comment. Thanks.

UPDATE : Question is not full duplicate of any question on stackoverflow.

10
  • possible duplicate of Open links in new window using AngularJS Commented Jun 26, 2015 at 7:13
  • @SagarNaliyapara: I had given visit to mentioned link, It is not totally duplicate. Try to read the post, please. Commented Jun 26, 2015 at 7:30
  • Are you making a hybrid application? Commented Jun 26, 2015 at 7:42
  • See, I am new to angularjs, so trying to do somethings separately, and its also the need. You can say its hybrid. At this moment this is just task, that I have to implement! Commented Jun 26, 2015 at 7:43
  • Check this plunker and tell me if this the behaviour you're looking for? here Commented Jun 26, 2015 at 7:56

3 Answers 3

0

if you wanted to do it in an angular way you could do something like this

angular.module('myApp', [])
    .controller('myController', ['$scope', '$window', function($scope,$window) {
  $scope.openWindow = function(greeting) {
    $window.open("http://www.google.com", "", "width=640, height=480");
  };
}]);

HTML Code

<div ng-controller = "myController"> 
<a title="Edit in new window" ng-click="openWindow() >Test edit</a>
</div>
Sign up to request clarification or add additional context in comments.

8 Comments

Nice, I think it will work for open new window, but how to pass user_id to that new window?
You will not be able to do this with AngularJS.
@skubski: There must be some solution for this!
You're trying to use a single page application as a multi page application. You will need to let your PHP framework handle the routing between the multiple SPA's you're building. You can retrieve the URL in JS with: window.location.href or document.URL. And you will need to parse the ID from that URL.
So problem is : how to pass that ID to URL,.
|
0

In angular js you can do something like,

 $scope.newWindow = function(value) {
    $window.open("http://your_url/routing_path/?key=value", "");
  };

where routing_path will be ur routing url and value is the part where you actually send your value.

In your script you can have like

var myApp = angular.module('myApp', []);
myApp.run(function($rootScope, $location, $http, $timeout) {

 $rootScope.$on('$routeChangeStart', function(event, next) {

     if (next.originalPath === 'your_routing_url') {
        var value = next.params.key;
     }
    });
});

13 Comments

Whatever value which we pass as the parameter in the url will be available in this event. It should work.
There is no $routeChangeStart event.on booting your app, unless there are routes defined and you trigger a default path.
@skubski: there are no two ng-apps.
$routeChangeStart gets fired before any routing takes place. Please refer the angular js doc docs.angularjs.org/api/ngRoute/service/$route
@SujVan: the html opened in a blank target will not be a part of your primary ng-app.
|
0

Also you can use Web Storage object like,

        var myApp = angular.module('myApp', []);
    myApp.factory('anyService', function($http, $location) {

    return {
    set: function(key,value) {
        return localStorage.setItem(key,value);
    },
    get: function(key) {
        return localStorage.getItem(key);
    },
    destroy: function(key) {
        return localStorage.removeItem(key);
    }       
    };
    });

inject the service any where and get the data.

1 Comment

localStorage is the browser object which will be present even after the browser is closed. So use and remove it as per your requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.