AngularJS pass Javascript object to controller -
i'm trying pass javascript object angularjs controller , having no luck.
i've tried passing init
function:
<div ng-controller="gallerycontroller" ng-init="init(jsobj)">
and on controller side:
$scope.init = function(_jsobj) { $scope.externalobj = _jsobj; console.log("my object.attribute : " + _jsobj.attribute ); };
though above doesn't seem work.
alternatively, i've tried pulling attribute angularjs controller interested in use in inline <script>
tag:
var jsobj.parameter = $('[ng-controller="gallerycontroller"]').scope().attribute ; console.log("my object.parameter: " + jsobj.attribute );
can tell me: best practice regarding this?
i don't have option rewrite plain javascript object part of 3rd party library.
let me know if need provide further clarification , in advance guidance!
-- johndoe
try setting value:
angular.module('myapp') .value('jsobj', jsobj);
then inject controller:
angular.module('myapp') .controller('gallerycontroller', ['jsobj', function (jsobj) { ... }]);
Comments
Post a Comment