How to call factory methods from HTML in angularjs? -
in controller
have followed methods:
var ispaused = false; $scope.switcher = function (booleanexpr, truevalue, falsevalue) { return booleanexpr ? truevalue : falsevalue; }; $scope.ispaused = function () { return ispaused; };
and can call html like:
<body ng-controller="cntrl"> ... <h4> {{ switcher( ispaused(), 'search address mode', 'search location mode' )}} </h4> <div class="btn-group"> ... </div>
as see if ispaused()
returns false
<h4>search location mode</h4>
this utility therefore want define factory
feederlitemodule.factory('switcher', function () { return { sw: function (booleanexpr, truevalue, falsevalue) { return booleanexpr ? truevalue : falsevalue; } }; });
no exceptions
when try call like:
<h4> {{ switcher.sw( ispaused(), 'search address mode', 'search location mode' )}} </h4> <div class="btn-group"> ... </div>
nothing happens.
**i added 'switcher'
controller.
how can call factory method html?
(*you welcome change/edit question if seems not clear)
thank you,
well, you're not supposed that... can put service object in property on $scope, , call there.
app.controller('myctrl', function($scope, switcher) { $scope.switcher = switcher; });
Comments
Post a Comment