javascript - Angular.js | Sharing a ngModel -


so, html.

<input type="text" id="ghusername" ng-model="username" placeholder="github username...">     <span id="ghsubmitbtn" ng-click="getusers()">pull user data</span> 

this controller a.

app.controller("homecontroller", ["$scope", "$http", function ($scope, $http) {     $scope.getusers = function () {         $http.get("https://api.github.com/users/" + $scope.username)           .success(function (data) {               //some stuff           }) 

and b (for posting sake). how username on html ngmodel, can show in controller? ex:

app.controller("reposcontroller", ["$scope", "$http", function ($scope, $http) { $scope.getrepos = function () {     $http.get("https://api.github.com/users/" + $scope.username + "/repos")         .success(function (data) {             // stuff         }) }; 

i've tried user services, factories , $rootscopes, don't seem work, help? btw, if wasn't clear tell me , edit post, thank you.


edit: ended using $rootscope, know isn't best idea minor thing. i'll keep answers reference tho, i'm sure work i'm dumb implement them.. thank you.

you must refernce $rootscope controllers:

app.controller("homecontroller", ["$scope", "$http","$rootscope", function ($scope, $http, $rootscope) ... 

and after access rootscope variables:

controller1: $rootscope.somevalue = "some value"; controller2: $scope.controllerscopevalue = $rootscope.somevalue;


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -