javascript - AngularJS codes structure. Are they any difference? -


new in angularjs, know pros , cons between codes below? recommended use?

$routeprovider.when('foo', {     templateurl: 'foo.html',     controller: fooctrl      function fooctrl() {         //something here     } }); 

or

$routeprovider.when('foo', {     templateurl: 'foo.html' });  app.controller("fooctrl", function() {     //something here });  //in html <div ng-controller="fooctrl"></div> 

i prefer second approach, , use when developing our application. elegant way of coding , seperating routes-configuration, module-wiring etc controllers. can write routes-config in main file app.coffee [i use coffeescript] defining

routesconfig = ($route) ->     $route.when('/employees',         {templateurl: 'employee.employeeview.html'}) 

define routesconfig , wiring modules [eg: employee.employeecontroller] here.

modules = ['employee.employeecontroller', 'user.usercontroller'] 

you can create, start angular application here,

m = angular.module('app', modules) m.config['$route', routesconfig] 

now can specify controllers seperately, in employeecontroller.coffee

name = 'employee.employeecontroller' mod = angular.module(name, []) mod.controller(name, [     '$scope'     '$log'     ($scope, $log) ->           $scope.name = 'java' 

in view, employeeview.html

<div ng-controller="employee.employeecontroller">  <div class ="info">   name {{name}}  </div> 

basically seperated controllers, view , application configuration each other.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -