Angular ctrl as

by sheilak

HTML

<div ng-app="app" ng-controller="ctrl as vm">
    <div ng-repeat="idea in vm.ideas">
        <div ng-show = "idea.description.length > vm.maxIdeaDescLength && vm.openLongIdea !== idea._id">
            {{idea.description.substring(0, vm.maxIdeaDescLength) }} 
            <a href='' ng-click='vm.openLongIdea = idea._id'> show all </a>
        </div>
         <div ng-show = "idea.description.length <= vm.maxIdeaDescLength || vm.openLongIdea === idea._id">
             {{idea.description}}
        </div>
    </div>
</div>

JavaScript

var app = angular.module("app", []);
app.controller('ctrl', function () {
    var vm = this;
    vm.maxIdeaDescLength = 10;
    vm.ideas = [
        {_id : 0, description :'abcd efgh ijkl'},
        {_id : 1, description :'qwer tyui opzx'}
    ];
});