Last active
August 29, 2015 13:57
-
-
Save mgandin/9604192 to your computer and use it in GitHub Desktop.
Hello Angular World
This file contains 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
'use strict'; | |
var helloWorld = angular.module('helloWorld.app',['helloWorld.controllers','helloWorld.services','helloWorld.directives']); |
This file contains 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
'use strict'; | |
var Controllers = angular.module('helloWorld.controllers',['helloWorld.services']); | |
Controllers.controller('HelloController',function ($scope,HelloService) { | |
$scope.label = "Angular"; | |
$scope.compteur = 0; | |
$scope.updateLabel = function() { | |
HelloService.getHello(function() { | |
$scope.label = "Angular FTW !!"; | |
}); | |
$scope.jqueryMessage = "JQuery FTW !!"; | |
$scope.refresh(); | |
}; | |
}); |
This file contains 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
'use strict'; | |
var Directives = angular.module('helloWorld.directives',[]); | |
Directives.directive('helloDirective',function() { | |
return function (scope, element, attrs) { | |
scope.refresh = function() { | |
if(scope.jqueryMessage == null) { | |
$(element).html("angular"); | |
} | |
$(element).html(scope.jqueryMessage); | |
} | |
scope.refresh(); | |
} | |
}); |
This file contains 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
'use strict'; | |
describe("HelloController", function() { | |
var isTrue; | |
var helloController; | |
var scope; | |
beforeEach(angular.mock.module('helloWorld.app')); | |
beforeEach(angular.mock.inject(function($rootScope, $controller){ | |
scope = $rootScope.$new(); | |
isTrue = true; | |
helloController = $controller('HelloController', {$scope: scope}); | |
scope.refresh = function() { | |
console.log("TADA !"); | |
}; | |
})); | |
it("should check the controller say something", function() { | |
expect(scope.label).toEqual("Angular"); | |
scope.updateLabel(); | |
expect(scope.label).toEqual("Angular FTW !!"); | |
}); | |
}); |
This file contains 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 ng-app="helloWorld.app"> | |
<head> | |
<title>Hello world</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="description" content="hello world FTW !!"> | |
</head> | |
<body> | |
<form data-ng-controller="HelloController"> | |
<label ng-style="{color:'gray'}">LABEL :: {{label|uppercase}}</label> | |
<input type="text" data-ng-model="label"/> | |
<button data-ng-click="updateLabel()">update</button> | |
<div id="hello" hello-directive> | |
</div> | |
</form> | |
</body> | |
<script src="js/angular/angular.js"></script> | |
<script src="js/jquery/jquery-1.11.0.min.js"></script> | |
<script src="js/app/services.js"></script> | |
<script src="js/app/directives.js"></script> | |
<script src="js/app/app.js"></script> | |
<script src="js/app/controller.js"></script> | |
</html> |
This file contains 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
// Karma configuration | |
// Generated on Fri Dec 06 2013 10:40:07 GMT+0100 (Paris, Madrid) | |
module.exports = function(config) { | |
config.set({ | |
// base path, that will be used to resolve files and exclude | |
basePath: '../../..', | |
// frameworks to use | |
frameworks: ['jasmine'], | |
// list of files / patterns to load in the browser | |
files: [ | |
'poc/karma/js/angular/angular.js', | |
'poc/karma/js/angular/angular-mocks.js', | |
'poc/karma/js/app/app.js', | |
'poc/karma/js/app/controller.js', | |
'poc/karma/js/app/services.js', | |
'poc/karma/js/app/directives.js', | |
'poc/karma/js/test/spec/HelloControllerSpec.js' | |
], | |
// list of files to exclude | |
exclude: [ | |
], | |
// test results reporter to use | |
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | |
reporters: ['progress', 'junit'], | |
junitReporter: { | |
outputFile: 'target/surefire-reports/karmaUnit.xml' | |
}, | |
// web server port | |
port: 9876, | |
// enable / disable colors in the output (reporters and logs) | |
colors: true, | |
// level of logging | |
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | |
logLevel: config.LOG_INFO, | |
// enable / disable watching file and executing tests whenever any file changes | |
autoWatch: true, | |
// Start these browsers, currently available: | |
// - Chrome | |
// - ChromeCanary | |
// - Firefox | |
// - Opera (has to be installed with `npm install karma-opera-launcher`) | |
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) | |
// - PhantomJS | |
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) | |
browsers: ['PhantomJS'], | |
// If browser does not capture in given timeout [ms], kill it | |
captureTimeout: 60000, | |
// Continuous Integration mode | |
// if true, it capture browsers, run tests and exit | |
singleRun: false | |
}); | |
}; |
This file contains 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
'use strict'; | |
var Services = angular.module('helloWorld.services',[]); | |
Services.factory('HelloService',function() { | |
var instance = {}; | |
instance.getHello = function(callback) { | |
callback(); | |
}; | |
return instance; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment