将requires.js与angular.js一起使用

时间:2016-09-01 10:51:47

标签: javascript angularjs requirejs

我是require.js中的新手,我正在使用angular.js实现requier.js,但是我收到了错误。这是我的代码:

配置文件:

require.config({
    paths: {
        angular: 'https://code.angularjs.org/1.5.5/angular.min',
        angularRoute: '//rawgit.com/angular-ui/ui-router/0.2.15/release/angular-ui-router.min',
        angularAnimate: '//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min',

    },
    shim: {
        'angular' : {'exports' : 'angular'},
        'angularRoute': ['angular'],
        'angularAnimate': ['angular']
    },
    priority: [
        "angular"
    ],
});

require([
    'angular',
    'app',
    'controllers/first-controller',
        'controllers/second-controller',
        'controllers/third-controller',
        'services/services',
        'directives/directives'
    ], function(angular, app) {
        var $html = angular.element(document.getElementsByTagName('html')[0]);
        angular.element().ready(function() {
            // bootstrap the app manually
            angular.bootstrap(document, ['WalletHubApp']);
        });
    }
); 

这是我的app文件:

define(['angular'], function (angular) {
    var app = angular.module('app', ['ui.router','ngAnimate']);

WalletHubApp.config(function($stateProvider, $urlRouterProvider) {

    $urlRouterProvider.otherwise('/walletHub/1/');

    $stateProvider

        .state('test', {
            url: '/walletHub/:id/{folderPath:[a-zA-Z0-9/]*}',
           templateUrl: function ($stateParams){
                return  "templates/"+$stateParams.id + '.html';
                },
            controllerProvider: function($stateParams) {
                console.log($stateParams)
              var ctrlName = $stateParams.id + "Controller";
              return ctrlName;
          }
        });

    });    
 return app;
});

这是控制器文件:

define(['app'], function(app) {
    WalletHubApp.controller('1Controller', function ($scope,$stateParams,$stateParams,$state,$http) {
 $http.get('sample.json')
       .then(function(res){
         $scope.persons = res.data              
        });


    var parts = $stateParams.folderPath.split('/')
    $scope.params = false;
    if(parts[0] != "")
    {
        $scope.parts = parts;
        $scope.params = true;

    }   
  })
return;
});

我不知道这段代码有什么问题。请帮我理清这个

1 个答案:

答案 0 :(得分:0)

根据官方document

  

通常最好避免在模块名称中编码,只需让优化工具在模块名称中刻录。

store.DatabaseCommands.Put(updatedKey, null, document.DataAsJson, newMetadata);
store.DatabaseCommands.Delete(oldKey, null);