i trying create angular.js calculator, return user root page if factory data object empty. issue cannot figure out how access data.terms
object see if empty inside of $routeprovider
configuration under /condition
path.
in code below, section says if (!data.terms)
not working. want return value of terms stored in factory data function:
// creating module var myapp = angular.module("app-calculator", ["calculatorcontrols", "ngroute"]) .config(function ($routeprovider) { $routeprovider.when("/", { controller: "termscontroller", controlleras: "vm", templateurl: "/content/templates/termsview.html" }); $routeprovider.when("/condition", { controller: "conditioncontroller", controlleras: "vm", templateurl: "/content/templates/conditionview.html", resolve: { mess: function ($location) { // check if data.terms field has been completed, // if not return root path. if (!data.terms) { $location.path('/'); } // } } }); // data myapp.factory('data', function () { var terms = ''; return { terms: terms, } })
you should inject data
dependency in resolve section.
var myapp = angular.module("app-calculator", ["calculatorcontrols", "ngroute"]) .config(function ($routeprovider) { $routeprovider.when("/", { controller: "termscontroller", controlleras: "vm", templateurl: "/content/templates/termsview.html" }); $routeprovider.when("/condition", { controller: "conditioncontroller", controlleras: "vm", templateurl: "/content/templates/conditionview.html", resolve: { mess: function ($location, data) { // check if data.terms field has been completed, // if not return root path. if (!data.terms) { $location.path('/'); } // } } });
Comments
Post a Comment