$watch under ion-content tag doesn't work [Solved]

I met a problem about $watch works with ng-modle under ion-content, attach code.


<!DOCTYPE html>
<html ng-app="app">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="cordova.js"></script>
    <script src="test.js"></script>
    <meta charset=utf-8/>
<body ng-controller="MainCtrl">
        <input ng-model="name"/>


app = angular.module('app', ['ionic']);

app.controller('MainCtrl', function($scope) {
    $scope.name = "Angular";

    $scope.$watch('name', function()

In this example, $watch doesn’t work, can’t listen ng-model changes, if you comment in test.html, $watch works right.

Is it a bug of ionicframwork or am I wrong. How to fix it?

I think you can not access variables directly over ng-model.

A model is an object.

Try something like:

$scope.data = {
name: ‘Angular’

and set watcher, ng-model to data.name

1 Like

Thank you, it works for me!


This trick fix the problem.

But, for anyone that want more information about whats works and whats don’t i found a useful codepen