私は 2 番目のアプローチを好み、アプリケーションを開発するときに使用します。これは、コントローラーからルート構成、モジュール配線などを分離する、エレガントなコーディング方法です。私たちはメインファイルにルート構成を書くことができますapp.coffee [私はcoffeescriptを使用します]のように定義します
routesConfig = ($route) ->
$route.when('/employees',
{templateUrl: 'employee.employeeView.html'})
ここで、routesconfig とワイヤリング モジュール [例: employee.employeeController] を定義します。
modules = ['employee.employeeController', 'user.userController']
ここからangularアプリケーションを作成して開始できます。
m = angular.module('app', modules)
m.config['$route', routesConfig]
たとえば、 employeeController.coffeeでコントローラーを個別に指定できるようになりました。
name = 'employee.employeeController'
mod = angular.module(name, [])
mod.controller(name, [
'$scope'
'$log'
($scope, $log) ->
$scope.name = 'java'
あなたのビューで、employeeView.htmlと言います
<div ng-controller="employee.employeeController">
<div class ="info">
Name is {{name}}
</div>
基本的に、コントローラー、ビュー、アプリケーション構成を互いに分離しました。