Skip to content

Instantly share code, notes, and snippets.

@NrI3
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save NrI3/03a2ef1eb28d8fc5fe1e to your computer and use it in GitHub Desktop.

Select an option

Save NrI3/03a2ef1eb28d8fc5fe1e to your computer and use it in GitHub Desktop.
/*
* by Jsn
* jason.scz@gmail.com
*/
/* app.js - angularjs */
var app = angular.module('Aplication',[]);
app.controller('MyController',function($scope){
$scope.publicPerson={
name: 'Daniela',
lastname: 'Fernandez'
};
$scope.fnPublic = function(){
alert(' I hope it help u :) ');
};
/* Private Object into MyController */
this.person = {
name: 'Alison',
lastname: 'Fernandez C.'
};
/* Private Function into MyController */
this.fnTest = function(){
$scope.publicPerson = {
name:'Jason',
lastname:'Fernandez C.'
}
};
});
/* Documento BODY html */
<input type="button" id="buttonBeta" value="TestMe:P">
<section id="idController" ng-controller="MyController as test">
<div>{{one}}</div>
<div>{{publicPerson}}</div>
<div>{{test.person}}</div>
</section>
/* JQuery Script - into another script resource */
$(document).ready(function(){
var scope = angular.element($('idController')).scope();
/* Show all information from scope object */
console.log(scope);
$('#buttonBeta').click(function(){
/* Sending data to scope {{one}} */
scope.one = "Jsn was here";
/* Updating DOM view */
scope.$apply();
/* Executing fnTest from MyController */
// Note: Remember MyController alias in HTML document "test"
scope.test.fnTest();
scope.$apply();
/* Getting a private objecto from MyController */
var aPerson = scope.test.person;
console.log(aPerson);
/* Getting a public person from HTML document or angular model {{publicPerson}} */
var pPerson = scope.publicPerson;
console.log(pPerson);
/* Executing public function */
scope.fnPublic();
scope.$apply();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment