Skip to content

Instantly share code, notes, and snippets.

@alber70g
Last active November 9, 2015 16:19
Show Gist options
  • Save alber70g/a3143e19840ebf2cd614 to your computer and use it in GitHub Desktop.
Save alber70g/a3143e19840ebf2cd614 to your computer and use it in GitHub Desktop.
AngularJS: Using partial html for Forms
module app {
'use strict';
angular
.module('app.entity')
.config(routes);
routes.$inject = ['$stateProvider'];
function routes($stateProvider: ng.ui.IStateProvider) {
$stateProvider
.state('entity', {
url: '/entity',
controller: 'app.entity.entityController',
controllerAs: 'entity',
templateUrl: 'components/entity/entity.html',
abstract: true
})
.state('entity.list', {
url: '/list',
controller: 'app.entity.entityListController',
controllerAs: 'entityList',
templateUrl: 'components/entity/entityList.html'
})
.state('entity.edit', {
url: '/edit/:transactionNr',
controller: 'app.entity.entityEditController',
controllerAs: 'entityForm', // EntityForm
templateUrl: 'components/entity/entityEdit.html'
})
.state('entity.new', {
url: '/new/:transactionNr',
controller: 'app.entity.entityNewController',
controllerAs: 'entityForm', // EntityForm
templateUrl: 'components/entity/entityNew.html'
})
/*inject:routes*/
;
}
}
<form name="entityCreateForm">
<div ng-include="partials/entityForm.html">
// this is now bound to the entityCreateController using controllerAs:entityForm
</div>
</form>
<form name="entityEditForm">
<div ng-include="partials/entityForm.html">
// this is now bound to the entityEditController using controllerAs:entityForm
</div>
</form>
<input name="field1" ng-model="entityForm.entity.field1">
<input name="field2" ng-model="entityForm.entity.field2">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment