Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass ng-model attribute to custom directive

So, I have a form, where I need to use a custom directive. What i need: pass the user model to the directive.

<form>
    <input type="text" ng-model="user.login">
    <input type="password" ng-model="user.password">

    <span ng-custom-directive ng-model="user.testfield"></span>

</form>

Directive template looks like this:

<span><input type="checkbox" ng-model="[HERE I NEED user.testfield TO WORK WITH user]"> </span>

How I can pass the user model to directive template?

After form submit I need user.testfield to be avaliable in the $scope.user like:

console.log($scope.user)
{
    login: 'test',
    password: 'test',
    testfield: true|false
}
like image 650
coldmind Avatar asked Nov 03 '14 15:11

coldmind


1 Answers

You can solve it in the other way plunker

In brief:

scope: {
    bindedModel: "=ngModel"
},
template: '<input type="text" ng-model="bindedModel">'
like image 71
Volodymyr Pavlenko Avatar answered Oct 15 '22 05:10

Volodymyr Pavlenko