-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poor usages of $scope in MainCtrl and HMTL #22
Labels
Comments
It is always a bad idea to use your
See myModule.controller('MainCtrl', function( models, utils )
{
var statusIndices = utils.buildIndex(models.statuses, 'name'),
typeIndices = utils.buildIndex(models.types , 'name'),
vm = this;
vm.current = models.current; // Data
vm.stories = models.stories;
vm.types = models.types;
vm.statuses = models.statuses;
vm.select = onSetAsCurrent; // Event Handlers
vm.createStory = onCreateStory;
vm.setCurrentStatus = onSetCurrentStatus;
vm.setCurrentType = onSetType;
// *************************************
// Private Event Handlers
// *************************************
function onSetAsCurrent(story)
{
var current = models.current;
current.story = story;
current.status = statusIndices[ story.status ];
current.type = typeIndices[ story.type ];
};
function onCreateStory()
{
models.createStory($scope.editedStory);
resetForm();
};
function onSetCurrentStatus( status, current )
{
current = current || models.current;
if ( current ) current.status = status.name;
};
function onSetType(type, current)
{
current = current || models.current;
if ( current ) current.type = type.name;
};
}); |
Additionally - with the use of Controller as syntax, your HTML is considerable more easy to understand: <div ng-controller="MainCtrl as vm">
<div class="span4 sidebar-content">
<h2>Stories</h2>
<div class="story" ng-repeat="story in vm.stories" ng-click="vm.select(story)">
<h4>{{story.title}}</h4>
<p>{{story.description}}</p>
</div>
<br>
<a class="btn" ng-click="vm.createStory()" ><i class="icon-plus"></i></a>
</div>
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the code:
The text was updated successfully, but these errors were encountered: