How can I add some small utility functions to my AngularJS application?

后端 未结 7 1783
情深已故
情深已故 2020-12-02 03:46

I would like to add some utility functions to my AngularJS application. For example:

$scope.isNotString = function (str) {
    return (typeof str !== \"strin         


        
7条回答
  •  悲&欢浪女
    2020-12-02 04:36

    Do I understand correctly that you just want to define some utility methods and make them available in templates?

    You don't have to add them to every controller. Just define a single controller for all the utility methods and attach that controller to or (using the ngController directive). Any other controllers you attach anywhere under (meaning anywhere, period) or (anywhere but ) will inherit that $scope and will have access to those methods.

提交回复
热议问题