angularjs - JavaScript angular controller get value from scope from another controller -
i have school task. have html code this:
<html ng-app="mytest"> <head><script type="text/javascript" src="../myscript.js"></script> </head> <body id="tst" class="textpage" ng-controller="testcontroller testcon"> <form class="" id="frm" ng-submit="dostuff()"> <div class="form-group"> {{testinfo}} </div> <div class="form-group"> <button type="submit" id="sbtn" name="sbtn">testsubmit</button> </div> </form> </body> </html> content of javascript name myscript.js this:
var tester = angular.module('mytest', ['ui.mask']); tester.controller('testcontroller', ['$scope', '$http', '$location', '$window', function ($scope, $http, $location, $window) { $scope.dostuff = function () { { $scope.testinfo = 'unknown value'; }; }; } ]); i have option add new javascript. not possible value $scope.testninfo. i cannot edit existing javascript , cannot edit html file. can add new javascript.
is there option how value $scope.testinfo in javascript?
thanks.
you can use broadcast
from controller 1 broadcast event
$scope.$broadcast('myevent',anydata); controller 2 receive our event
$scope.$on('myevent', function(event,anydata) { //code controller 2 }); here anydata represent object passed
Comments
Post a Comment