controller - Isolate and shared scope same time in directive AngularJS -


new angular not sure if ask question right way.

so have form.

<form ng-controller="mycontroller" action="" method="get">     <div mydirective>         <input ng-model="question.sex" value="male" type="radio">        <input ng-model="question.sex" value="female" type="radio">        <button ng-click="log(logthisquestionansware())"></button>     </div>     <div mydirective>         <input ng-model="question.agree" value="no" type="radio">        <input ng-model="question.agree" value="yes" type="radio">\        <button ng-click="log(logthisquestionansware())"></button>     </div> </form> 

so goal log current "question" answer. on button click.

how can access local question in mydirective separate second directive , have in controller scope too.

--[ edit: ]--

ok pretty scenario. http://jsfiddle.net/y5esnm09/5 each button have log own directive value not both radio values if selected.

if correctly understood question, want both directive instances bind same question object, have scopes separate eachother:

set 2 way data binding between directive , controller, e.g.:

<div my-directive question="question">  <!-- rest -->  angular.module('your.module').directive('mydirective', function() {    return {       scope: question: '=',        //other props    } 

this ensure both directives bind same question object have own separate scopes.

an alternative set scope property true, way both create child scope of controller.

edit: fiddle demonstrating 2 way binding:

http://jsfiddle.net/l0eqf4qe/

ps: converted mydirective my-directive, angular translate snake-case camelcase you.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -