Declaring private/internal functions and variables like you did is perfectly legitimate use of Javascript. You can even declare functions like this:
function controller( $scope ){
$scope.var;
var myvar = 'Hello world';
function myfunction(){
alert('Hello world');
}
}
Hi All,
Ok, maybe I’m weird, but doesn’t anybody see the obvious bug in here ;)
function controller( $scope ){
$scope.var;
var myvar = 'Hello world';
function myfunction(){
alert(myvar); // <----- I assume this is the needed code for this brilliant piece!!
}
}
On a serious note,
Yeah, this is perfectly valid, and I my opinion preferable above putting everything on the $scope!
Regards
Sander
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/PyXtGO2R-HA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
Jake,
That is something different! Probably those controllers are designed to be used with the controller-as constructor.
a sample say’s more then 1000 words:
js:
App.controller('somecontroller',function () {
this.name='Sander Elias'
});
html/template:
<div ng-controller='somecontroller as person'>Name : {{person:name}}</div>
This is also a form you can use. Also you can mix and match it with the $scope style!
Regards
Sander