I'm having some trouble with angular scopes within the context of a tab (Angular UI).
Here is my jsfiddle example (slimmed down example showing fields on multiple tabs with a single submit button outside of the tabs).
Here is the basic html layout:
<form...>
<tab>
<pane>
<input...>
</pane>
</tab>
</form>
Looking at the jsfiddle example, without the tabs if I submit a very basic form I would see the $scope.user be an object. Since the fields are within panes (tabs) the scope is incorrect. How can I get access to the submitted user object in createUser?
AngularJS Scope The scope is the binding part between the HTML (view) and the JavaScript (controller). The scope is an object with the available properties and methods. The scope is available for both the view and the controller.
The $scope in an AngularJS is a built-in object, which contains application data and methods. You can create properties to a $scope object inside a controller function and assign a value or function to it. The $scope is glue between a controller and view (HTML).
There are two types of Scope in AngularJS. The JavaScript function that makes/changes/removes/controls the data known as Controller.
The $ in "$scope" indicates that the scope value is being injected into the current context. $scope is a service provided by $scopeProvider . You can inject it into controllers, directives or other services using Angular's built-in dependency injector: module.
The problem is that the user
model is buried deep within an isolate scope. To get the code working as expected, you would need to alert
out the value of $scope.$$childHead.panes[0].$$nextSibling.user.first_name
not $scope.user
. This is obviously not a solution.
A simple solution is to add an empty user
object to the controller scope. The ng-model
directives in your HTML will then bind to this property. Your controller should look like this:
function MyCtrl($scope) {
$scope.user = {};
$scope.createUser = function () {
alert($scope.user);
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With