Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <parent>
- <label>Username: </label>
- <child></child>
- <button id="login" type="submit">Login</button>
- </parent>
- angular.module('sampleModule', [])
- .directive("parent",function(signOnService){return {
- restrict : 'E',
- transclude: true,
- scope: {},
- controller: function($scope, $element, $attrs){
- this.username = 'InitU';
- this.password = 'InitP';
- this.setUsername = function(name){
- this.username = name;
- };
- this.getUsername = function(){
- return this.username;
- };
- this.getPassword = function(){
- return this.password
- };
- this.setPassword = function(password){
- this.password = password;
- };
- this.check = function() {
- //TODO something on form submission
- };
- },
- controllerAs: 'diff',
- link: function(scope, element, attrs, ctrl){
- scope.user = ctrl.username;
- element.find('button').on('click', function(event){
- alert('Username: '+ ctrl.username + 'nPassword: '+ ctrl.password);
- });
- },
- template: '<form name="myForm" ng-submit="diff.check()"><ng-transclude></ng-transclude></form>'
- }})
- .directive("child",function(){
- return {
- restrict : 'E',
- require: '^parent',
- scope: false,
- link: function(scope, element, attrs, ctrl){
- scope.username = ctrl.getUsername();
- console.log('INI: '+ scope.username);
- scope.$watch('username', function(newVal, oldVal){
- if(newVal!=oldVal)
- //alert('Value Changed: '+ newVal);
- ctrl.setUsername(scope.username);
- });
- },
- template: '<input name="username" type="text" ng-model="username" required>'
- }
- });
- <parent>
- <label>Username: </label>
- <child></child>
- <button id="login" type="submit" ng-disabled="myForm.$invalid">Login</button>
- </parent>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement