logo
down
shadow

AngularJS: Pass object from directive to controller


AngularJS: Pass object from directive to controller

By : user2949938
Date : November 17 2020, 04:28 AM
I wish this help you You can do this in the link function of the direction. Since you want to set the value on the scope, you can use the scope parameter of the link function. You can also set the object on the controller, since The fourth argument (optional) argument to the link function is the controller for the directive.
code :
.directive('pTest', ['$compile', function($compile) {
    var object = {value: 'bla'};

    return {
        controller: 'test',
        link: function(scope, elements, attrs, controller) {
           scope.obj = object;
           // or
           controller.obj = object;
        }

    };
}]);


Share : facebook icon twitter icon
Pass object context back to controller callback from AngularJS Directive

Pass object context back to controller callback from AngularJS Directive


By : striverhong
Date : March 29 2020, 07:55 AM
I wish this help you Solution
Isolate scope binding should be declared with "&" instead of "=", thus resulting in scope.callBack() executing the updatePerson(person) given function.
How to pass object from controller to directive without using $scope in angularJS

How to pass object from controller to directive without using $scope in angularJS


By : user2291677
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can read more about the 'Controller as syntax' here: http://toddmotto.com/digging-into-angulars-controller-as-syntax/
Please note this syntax was introduced in angular 1.2. Your plunkr was using angular 1.0.x.
code :
<body ng-controller="MainCtrl as ctrl">
    {{ctrl.data}}
    <scroll-grid data="ctrl.data"></scroll-grid>
</body>
app.controller('MainCtrl', function() {
    this.data = [
        {
            time: '8/19/2014',
            id : 123,
            text : 'first'
        },
        {
            time: '8/18/2014',
            id : 456,
            text : 'second'
        },
        {
            time: '8/17/2014',
            id : 123,
            text : 'third'
        }
    ];
});
Pass array object from controller to custom directive in AngularJS

Pass array object from controller to custom directive in AngularJS


By : hoangdc79
Date : March 29 2020, 07:55 AM
it should still fix some issue You are using interestPoints: '@' as the method of binding interestPoints to the scope. That actually binds only the string {{points}} to interestPoints instead of actually evaluating that expression in the parent's scope.
Use the interestPoints: '=' as the binding method and then interest-points="points" to get the desired behaviour.
Load the JSON file from local by ANgularJS controller and pass it to ANgularJS custom directive scope

Load the JSON file from local by ANgularJS controller and pass it to ANgularJS custom directive scope


By : shahnurniloy
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am stuck in here. I went through few tutorials and Stack overflow questions and answers like here. ,
But its works fine when I hard coded in my controller
code :
 var cancelWatch = scope.$watch(function () {
        return scope.data;
    },
    function (newVal, oldVal) {
        if (newVal !== undefined ) {
            run();
            cancelWatch();  // in case if you want kill watcher
            }
    });
app.directive('barsChart', function(){
var rectBar = {
    restrict : 'EA',
    replace : true,
    scope : {data:'=chartData'},
    link : function(scope, element, attr){
        var barColor = 'steelblue';

     function run(){
       console.log(scope.data);
     }

     var cancelWatch = scope.$watch(function () {
        return scope.data;
    },
    function (newVal, oldVal) {
        if (newVal !== undefined ) {
            run();
            cancelWatch();
            }
    });


        }
    };
    return rectBar;
});
How to Pass parameter from AngularJS Directive to AngularJS controller function

How to Pass parameter from AngularJS Directive to AngularJS controller function


By : user1356925
Date : March 29 2020, 07:55 AM
like below fixes the issue In the case of an isolated scope, the directive scope is completely unaware of its parent’s scope.
To call a function of a controller you have to bind that function to the scope of directive and then call scope functions from inside the directive.
code :
app.controller('MainCtrl', function($scope) {

  $scope.commonFunc = function(passed){
    $scope.name = passed;
  };
});

app.directive('demodirective', function(){

  return {
    scope: {
      commonFunc: '&'
     },
    link: function(scope){
      scope.commonFunc({passed:"world"});
    }
  };

});
<body ng-controller="MainCtrl">
    <demodirective common-func="commonFunc(passed)">
    </demodirective>
    Hello {{name}}
</body>
Related Posts Related Posts :
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • How to animate the width of a div slowly with jquery
  • JavaScript + RegEx Complications- Searching Strings Not Containing SubString
  • SignalR - Unable to get property 'client' of undefined or null reference
  • full calendar not displaying when loaded (with backbone)
  • Angular: Update service and share data between controllers
  • ReplaceAll Google script
  • Search for matching LI items in separate UL
  • Access arguments of an... argument
  • Customizing Google custom search jsapi (query strings)
  • React | Can´t load Images > Module not found
  • Dynamically creating buttons in DOJO
  • 404 Not Found in AJAX post call
  • How do I find out, using javascript, what software opened and running my application?
  • Javascript to check the status of wireless connection
  • StarDict support for JavaScript and a Firefox OS App
  • Phonegap event Resume
  • call javascript function on ENTER key press?
  • When is the best time to remove no-js classes from the html tag
  • Recommended email sending languages
  • setInterval not working properly with chrome
  • Does IE create new scope for each script tag?
  • Uncaught SyntaxError: Unexpected token < Underscore and parse issues
  • How to pass captured URL to Email Body in HTML
  • How to structure default nested resources?
  • Store all the keys of a JSON object in a variable
  • Need an efficient way to group the Array of object in javascript
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org