Last active
October 8, 2021 08:52
Simple angularAMD Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['angularAMD', 'angular-route'], function (angularAMD) { | |
var app = angular.module("webapp", ['ngRoute']); | |
app.config(function ($routeProvider) { | |
$routeProvider | |
.when("/home", angularAMD.route({ | |
templateUrl: 'view_home.html', controller: 'HomeCtrl', controllerUrl: 'controller_home' | |
})) | |
.when("/view1", angularAMD.route({ | |
templateUrl: 'view_view1.html', controller: 'View1Ctrl', controllerUrl: 'controller_view1' | |
})) | |
.otherwise({redirectTo: "/home"}); | |
}); | |
return angularAMD.bootstrap(app); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['app'], function (app) { | |
app.controller('HomeCtrl', function ($scope) { | |
$scope.message = "Message from HomeCtrl"; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['app'], function (app) { | |
app.controller('View1Ctrl', function ($scope) { | |
$scope.message = "Message from View1Ctrl"; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="style.css"> | |
<script data-main="main.js" src="//marcoslin.github.io/angularAMD/js/lib/requirejs/require.js"></script> | |
</head> | |
<body> | |
<h1>Sample for <a href="http://marcoslin.github.io/angularAMD/" target="_blank">angularAMD</a></a></h1> | |
<div ng-view></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.config({ | |
baseUrl: "", | |
// alias libraries paths. Must set 'angular' | |
paths: { | |
'angular': '//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min', | |
'angular-route': '//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.min', | |
'angularAMD': '//cdn.jsdelivr.net/angular.amd/0.2.0/angularAMD.min' | |
}, | |
// Add angular modules that does not support AMD out of the box, put it in a shim | |
shim: { | |
'angularAMD': ['angular'], | |
'angular-route': ['angular'] | |
}, | |
// kick start application | |
deps: ['app'] | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Styles go here */ | |
h1 { | |
text-align: center; | |
} | |
h2 { | |
color: blue; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Home Page</h2> | |
<div>Message: {{message}}</div> | |
<hr> | |
<a href="#/view1">View1</a> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>View1</h2> | |
<div>View Message: {{message}}</div> | |
<hr> | |
<a href="#/home">Home</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after loading all the dependencies the app.js file raises an error as below
Uncaught Error: bootstrap can only be called once.
how we can solve it ?