Skip to content

Instantly share code, notes, and snippets.

@mandrasch
Created August 30, 2011 14:33
Show Gist options
  • Save mandrasch/1181031 to your computer and use it in GitHub Desktop.
Save mandrasch/1181031 to your computer and use it in GitHub Desktop.
Widgets: scope problem
function OrganizationManagementCreateCtrl($route,$location)
{
var self = this;
this.$route = $route;
this.test123 = 'XXX';
this.formtemplate = 'partial_form.html';
this.submit = function(){
alert(this.form.name);
}
}
OrganizationManagementCreateCtrl.$inject = ['$route','$location'];
<!-- does not work: -->
<my:input name="name" label="Name" ns="form"></my:input>
<!-- does work: -->
<!-- <input type="text" name="form.name" /> -->
<!-- is inserted: -->
{{test123}}
<button ng:click="submit()">Erstellen</button>
<button ng:click="cancel()">Abbrechen</button>
<div ng:controller="OrganizationManagementCreateCtrl">
{{test123}}
<ng:include src="formtemplate"></ng:include>
<p><a href="#/organizationManagement/">&raquo; Zurück</a></p>
</div>
angular.widget('my:input', function(element) {
this.descend(true);//2DO: does child processing?
var name = element.attr('name');
var label = element.attr('label') || name;
var ns = element.attr('ns') || 'form'; //the namespace to use
element.append('<div class="form_field">'+
'<label for="'+ns+'.'+name+'">'+label+':</label>'+
'<input type="text" name="'+ns+'.'+name+'" />'+
'<span class="form_error" ng:show="'+ns+'.errors.'+name+'">{{'+ns+'.errors.'+name+'}}</span>'+
'</div>'
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment