0

I want to append a template when the user presses a button. I also want to invoke the corresponding controller. Unfortunately I dont have any idea how to to that.

Can anybody help?

2 Answers 2

1

You can just append your template and create a new scope for. Afterwards you just need to compile it in order to invoke the controller.

So after you have appended your template:

var new_scope = $scope.$new();
$compile( $tmpl ) ( new_scope );

That also invokes your controller

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

Comments

1

Use a Routes Application:

var application = {};

var App = angular.module('application');

App.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/products', { templateUrl: 'views/products/list.html', controller: ProductsControllers })
        .when('…', { templateUrl: '…', controller: ... });
}]);

After only link to "/products" for example.

5 Comments

Thank you but that is not what i need. I want to append a view to the app. I do not want to replace a view
@user3518571 You can have just one ng-view. So, you can change its content in several ways: ng-include, ng-switch or mapping different controllers and templates through the routeProvider.
@user3518571 This library can help you. Its uses the partials to append views, see in github.com/angular-ui/ui-router
so there is no way to click a button, append a template to the view and invoke the corresponding controller?
@user3518571 its possible to have said in the above comments.

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.