Configurable Bits need a Provider
We want to is able to configure the characterLength
before Tweetable
runs. Refactor the Tweetable
factory into a provider and expose a function, that would allow setLength()
us to set a with our characterLength
app config.
Angular.module (' Notewrangler '). Factory (function tweetablefactory ($http) { var characterlength = 144; return function (potentialtweet) { return $http ({ ' POST ', '/http/ Gentle-spire-1153.herokuapp.com/tweet ', data: { description:potentialtweet, maxLength: Characterlength } });
Change the factory definition into a provider definition.
function Tweetableprovider ($http) {
Wrap the existing function returned by we TweetableProvider()
function in a call to the $get()
function required by providers. Don ' t forget to move the $http
service injection!
Angular.module (' Notewrangler '). Provider (' tweetable ', [function tweetableprovider () { var characterlength = 144; This function ($http) { returnfunction(potentialtweet) { return $http ({ ' POST ', ' Http://gentle-spire-1153.herokuapp.com/tweet ', data : { description:potentialtweet, maxlength:characterlength}};};}; }]);
Create a setLength()
function attached to the provider that sets the characterLength
variable.
Angular.module (' Notewrangler '). Provider (' Tweetable ', [functionTweetableprovider () {varCharacterlength = 144; This. $get =function($http) {return function(potentialtweet) {return$http ({method:' POST ', URL:' Http://gentle-spire-1153.herokuapp.com/tweet ', data: {Description:potentialtweet, maxlength:characterlength}}); }; }; This. SetLength =function(length) {characterlength=length; };}]);
Configuring the Tweet Length
Now this our provider are ready for go, let's call the setLength()
method of TweetableProvider
Configure the acceptable maximum tweet length . Instead of 144 characters, we need to allow for a characterLength
.
Let's call on our config()
NoteWrangler
module and provide it an anonymous function.
Inject into the TweetableProvider
config()
function.
Call the function of the from setLength()
TweetableProvider
within the function and config()
pass it a value of.
Angular.module (' Notewrangler ', [' Ngroute ']). config (function(tweetableprovider) { Tweetableprovider.setlength (+);});
link:https://code.google.com/p/crypto-js/
[AngularJS + Cryptojs + Gravatar] Provider vs Factory