If the function is defined as
function myFunction(){...} then on the iPhone Chrom gives an error. What - I do not know, because. There is no possibility to look at the console. But the execution of AngularJS stops. If the function is defined as
var myFunction = function(){...} That's all fine.
Has anyone encountered this problem and how can it be circumvented, otherwise there are a lot of definitions of the first type in the code?
More code in the question: Minimum working code:
var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.newVar = "Its not work"; $scope.myFunction = function() { return $scope.newVar = 'Its work'; }; $scope.myFunction(); }); <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="personCtrl"> <span> Angular <span ng-if="0">не </span> работает </span> <br /> <span ng-bind="newVar"> Its not work </span> </div> </body> </html> And this code:
var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.newVar = "Its not work"; $scope.myFunction = myFunction; function myFunction() { return $scope.newVar = 'Its work'; }; $scope.myFunction(); }); <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="personCtrl"> <span> Angular <span ng-if="0">не </span> работает </span> <br /> <span ng-bind="newVar"> Its not work </span> </div> </body> </html> It works on all devices except the iPhone (I can’t check it out right now, I’ll check it on Monday and make corrections)
Roman: You are right, and thank you for adding the code I have shortened (angular etc subconnect). What you wrote will work, incl. on the iPhone. But the style you applied in this place:
$scope.myFunction = function() { return $scope.newVar = 'Its work'; }; It is considered not the best (as it seemed to me). It is usually recommended to do so (long look for the link):
$scope.myFunction = myFunction; function myFunction() { return $scope.newVar = 'Its work'; }; But, suddenly it turned out that on the iPhone it does not work. The question is how to get around this so as not to rewrite all the code?
"use strict"- Grundy