Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

How can I pass data in two partial html files using angularJS, totally weird cant get through it.

I have one index file [fine.], I login and reach view5 [partials/blog.html] which is written in DemoCtrl [Fine], all works fine till now. Now when I click on the link in blog.html, it goes to next page but doesnt show any $scope data which I have set in the controller.

HTML code of partial file: {{post.postText}}

    <div class="blog-meta clearfix">
     <p class="pull-left">
         <i class="icon-user"></i> by <a href="#">{{ post.firstName }} {{ post.lastName }}</a> | <i class="icon-folder-close"></i> Category <a href="#">Food</a> | <i class="icon-calendar"></i> {{post.createdDate.millis | date:'MM/dd/yyyy @ h:mma'}}
     </p>
     <p class="pull-right"><i class="icon-comment pull"></i> <a href="#/view18#comments" data-ng-click="postDetails(post)">3 Comments</a></p>
     </div>

*Controller Code *

    app.controller('DemoCtrl', ['$scope', 'Post', 'ezfb', '$window', 'PFactory', 'PostFactory', '$location', '$timeout', function ($scope, Post, ezfb, $window, PFactory, PostFactory, $location, $timeout) {
        $scope.postDetails = function (post) {
                $scope.postdetail = {id: null};
                $scope.postdetail = post;
                $location.path('/view18');
            }
    }]);    

* app.js *

    $routeProvider.when('/view5', {templateUrl: 'nova/blog.html', controller: 'DemoCtrl'});
    $routeProvider.when('/view18', {templateUrl: 'nova/blog-item.html', controller: 'DemoCtrl18'}); 

postDetails(post) method in called in DemoCtrl with post object and that post object is been set in $scope.postdetail variable in $scope.postDetail method and view is different template. I can see data coming fine in console in the controller and postDetails method but it is not displayed in template.

share|improve this question

You can't access data set to scope in one controller in another controller/template.

Use a service and hold/set data in the service and use the service in your DemoCtrl18 to get the data that you set in DemoCtrl

Or use angaular ui-router to get more features like parent-child states and scope inheritance and more.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.