Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs Two way binding issues
    primarykey
    data
    text
    <p>I'm trying to create a dynamic directive that will receive his binding options from attributes. This is my controller view:</p> <pre><code>&lt;div ng-controller="OtCtrl"&gt; &lt;div ng-include src="'/client/views/openTradeView.html'"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>my View:</p> <pre><code>&lt;div&gt; {{name}} &lt;div swings binding="Risk" title="Risk"&gt;&lt;/div&gt; &lt;div swings binding="Amount" title="Amount"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is my directive View:</p> <pre><code>&lt;div&gt; {{title}} &lt;a href="javascript:void(0)" ng-click="minus()"&gt;-&lt;/a&gt; {{amount}} &lt;a href="javascript:void(0)" ng-click="plus()"&gt;+&lt;/a&gt; &lt;/div&gt; </code></pre> <p>This is my directive:</p> <pre><code>app.directive("swings", function () { return { replace: true, scope: { title : '@title', amount: '=binding', extra: '=bindingExtra' }, resctrict: "A", controller: function($scope){ $scope.minus = function (event, binding) { $scope.amount -= 1; console.log(binding) } $scope.plus = function (event) { $scope.amount += 1; } }, templateUrl: '/client/views/swingsDirectiveView.html' } }); </code></pre> <p>And finally my Controller:</p> <pre><code>app.controller("OtCtrl", ['$scope', function ($scope) { $scope.Amount = 400; $scope.Risk = 100; setInterval(function(){ console.log($scope.Risk) },2000); }]); </code></pre> <p>I know that when I use ng-view, angularjs creates new scope. My issue that when I click plus or minus, the amount in the directive updates but the Risk model in the controller not, but on first load directive takes the risk init value and set the amount.</p> <p>How can I fix this issue.</p> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload