javascript - What are the advantages/disadvantages to a declarative template? ViewModel approach? -
when talking declarative syntax in angularjs bring directives, , how can pass $scope
properties down these directives processing, dom manipulation, data gathering , maybe various combination of those.
currently, i'm struggling convince team (let alone myself) declarative template right approach. doesn't mean using directives, how use directives.
the following controller/template pair shows example display element based on "model"/$scope's properties.
function maincontroller($scope) { $scope.hasjquery = true; $scope.hasproblems = true; $scope.haslodash = false; $scope.hasstuff = true; } <div ng-controller="maincontroller"> <span ng-if="hasjquery && hasproblems && haslodash && hasstuff">tl;dr?</span> <div>
but other approach may this
function maincontroller2($scope) { // get/retrieve $scope stuff... // setup "viewmodel" data $scope.hasjqueryandproblemsandlodashandstuff = $scope.hasjquery && $scope.hasproblems && $scope.haslodash && $scope.hasstuff; $scope.hasjqueryandlodash = $scope.hasjquery && $scope.haslodash; } <div ng-controller="maincontroller"> <span ng-if="hasjqueryandproblemsandlodashandstuff">...</span> <span ng-class="hasjqueryandlodash ? 'blue' : ''"></span> </div>
the name exaggerated version of possibly such isready
or hasall
point show html require multiple ng-class
attributes various logic rely on $scope
properties.
i see first example being people go - except in cases logic gets complex. plus know angularjs mvw doesn't me out.
should add "viewmodel" (presentation logic) $scope
in controller sometimes? time? never? , advantages/disadvantages of putting presentation logic controller/template?
Comments
Post a Comment