Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:09:33+00:00 2026-06-17T12:09:33+00:00

given the controller function ctl($scope, $http) { $scope.postForm = function() { console.log(submitting form) }

  • 0

given the controller

function ctl($scope, $http) {
  $scope.postForm = function() {
    console.log("submitting form")
  }
}

and the view

  <form name="pform" ng-show="!error.Show">
    <div ng-view></div>
    <button type='button' value='Save' ng-click="postForm()" />
  </form>

The controller method postForm doesn’t get called, however, if i move the form tag into the view the method is called. Is there a reason that this doesn’t work as I expect it to? Is there another way to accomplish the goal of sharing the form controls across different views?

Update

my module and routeProvider are configured like this:

angular.module("profilemodule", [])
.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when("/info", { templateUrl: '/partials/profile/info.html', controller: ProfileController })
        .when("/user", { templateUrl: '/partials/profile/user.html', controller: ProfileController })
        .when("/introduction", { templateUrl: '/partials/profile/editor.html', controller: ProfileController })
        .otherwise({ redirectTo: '/info' });
}]).run(function ($rootScope, $location) {
    $rootScope.location = $location;
})

and the page includes some nav elements which are set based on the location service like so:

<div class="row">
    <div class="offset2 span10">
        <ul class="nav nav-pills">
            <li ng-class="{active: location.$$path.substring(0, '/info'.length) == '/info'}"><a href="#/info" >Information</a></li>
            <li ng-class="{active: location.$$path.substring(0, '/user'.length) == '/user'}"><a href="#/user" >User</a></li>
            <li ng-class="{active: location.$$path.substring(0, '/intro'.length) == '/intro'}"><a href="#/intro" >Introduction</a></li>
        </ul>
    </div>
</div>

<form name="pform" method="POST" ng-show="!error.Show">
   <div ng-view></div>
   <button type='button' value='Save' ng-click="postForm()" />
</form>

the ng-class statements works perfectly, is it because I’ve set the location property of $scope in the module’s run method?

thanks,

jason

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:09:34+00:00Added an answer on June 17, 2026 at 12:09 pm

    ng-view with routing creates a new scope with the controller, and you can’t reach a child scope. Your submit action lies in the parent scope and the form data lies in the child scope (created by ng-view).

    If you want to use common form controls, you can use ng-include, this directive gets template it and renders that in the current scope.

    Move your form controls to a new template, then include them in all of your forms.

    API reference:
    http://docs.angularjs.org/api/ng.directive:ngInclude

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an application: Ext.application({ name: 'APP', appFolder: 'app', funcA: function() { console.log('called funcA'); },
Given a Controller class and a View class, is it better for the controller
I want to show a custom animation when pushing a view controller: I would
Given the following code: JE.events = { self: this, controller: { init: function(){ $(.monthheader).click(function
I want to redirect my '/' uri to a given controller's action. I used
Given I have a controller class as such: public class ResourceController : AuthorizedController {
In my controller i had given [ValidateInput(false)] for that particular Action in my return
Given a particular URL, how do I find out for sure which controller action
Given the following two defined routes: routes.MapRoute(name: CityCategoryPage, url: {city}-{state}/{categoryName}/__c/, defaults: new { controller
I have a function which retrieves a base64 encoded image from a controller and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.