Q:

Cannot read property of undefined when press button angular 1.x

sorry to ask a simple question here. But I really don't know how to fix it or why I got this error :(
I got this error use angular 1.x. What I want here is about make an alert when user press a button without input the title in the form.
Here's my code, I make it simpler btw :D 
index.html
<div class="form-group">
    <label for="">Title</label>
    <input type="text" ng-model="shipment_template.title" class="form-control">
</div>

<button ng-click="check">Check This</button>

And I put the logic in my controller:
shipmentTemplate.controller.js
if (typeof $scope.shipment_template.title == 'undefined') {

    console.log("success")
} else {

    alert("Please fill the title")
}

The problem is when I fill the input, I get the success in my console, But when I not fill it I don't get any alert, instead I got this error.
Cannot read property 'title' of undefined 
first I try it without use typeof, and use length, but it give the same error :(
Sorry for my bad english, and I hope you all can help me fix this guys :-D

A:

Just pass the model into your check function and that should do the trick:
HTML:
<div class="form-group">
 <label for="">Title</label>
 <input type="text" ng-model="shipment_template.title" class="form-control">
</div>

<button ng-click="check(shipment_template.title)">Check This</button>

JavaScript:
  $scope.check = function(input) {
    if (input) {
      console.log("success");
    }
    else {
      alert("Please fill the title");
    }
  }

It's also a clearer way to write the code you're trying to accomplish. Working Code: Plunkr

