0

I am trying to learn Angular js. I want to embed another website as a part of my webpage; inside a "div". I have the following code so far which does that for me.

However, the embedded website will have hyperlinks in it. When someone clicks on the hyperlinks,is there a way where the new contents are displayed inside the same div?

Is it possible?


<body ng-app="sampleApp">
    <div ng-controller="CommonController">
        <div>
            <a href="#" ng-click="show()">ShowPage</a>
        </div>
            <div ng-bind-html-unsafe="expression"/>
    </div>
    <script
        src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <script>
        var sampleApp = angular.module('sampleApp', []);
        sampleApp
                .controller(
                        'CommonController',
                        function($scope, $http) {
                            $scope.show = function() {
                                var responsePromise = $http
                                        .get("http://localhost:8080/HelpDynamic/spring/welcome");
                                responsePromise.success(function(data, status,
                                        headers, config) {
                                    $scope.expression = data;
                                });
                                responsePromise.error(function(data, status,
                                        headers, config) {
                                    alert("AJAX failed!");
                                });
                            }
                        });
    </script>
</body>

1 Answer 1

1

The easiest way to do it is by using ui-router instead of ng-router. This community built module allow you to use nested views. It means that you can integrate other templates inside the one you use.

To see how to do it, I recommend that you read its well-written guide about nested views : https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I am +1 ing you for now. I will read the link and try to incorporate tomorrow. Will let you know if any issues or accept the answer.

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.