javascript - Strange behavior concerning the sample Ionic ToDo app in the docs -
i'm new ionic framework , trying follow through ionic todo app demonstration. before starting want mention manually installed latest ionic release github page , included following in index.html: ionic.bundle.js, angular.min.js, angular-animate.min.js, angular-resource.min.js, angular-sanitize.min.js, angular-ui-router.min.js. in chapter 5, author details controller code create new task. tried adding functionality .createtask()method defined as
$scope.createtask = function(task) { $scope.tasks.push({ title: task.title }); $scope.taskmodal.hide(); task.title = ""; }; by changing to
$scope.createtask = function(task) { if (task.title == "") { window.alert("empty task!"); $scope.taskmodal.hide(); } else { $scope.tasks.push({title: task.title}) $scope.taskmodal.hide(); task.title = "" ; }; }; now, if run new code accompanying view outlined in tutorial, see controller calls empty task alert if task.title == "" fails! maybe i'm missing obvious, i'm not sure. furthermore, , main reason i'm writing post, if comment out line task.title = ""; in else clause , add task via live view, adds 2 instances of task created! bizarre, or thought, seems $scope.tasks.push({title: task.title}); being executed twice. programmer do, tried make compiler (in case interpreter) spill secrets. declared variable in controller scope, $scope.i = 0, keep track of happening. leaving //task.title = "" in place, inserted
$scope.i += 1; window.alert($scope.i); right before it. when run code, notice 2 things:
- the controller no longer calls empty task alert on non-empty tasks.
- the view updated 1 instance of created task.
so, i'm not sure what's happening. maybe it's careless error i've overlooked, on appreciated. many thanks!
edit:
i tried experimenting further , seems whole thing hinges on window.alert(). if
$scope.i += 1; window.alert($scope.i); is replaced with
$window.alert("1"); the "solution" still works. although if use window.alert() or window.alert("") original problem remains.
Comments
Post a Comment