AngularJS: Correct way to define a model? -


i trying find best way define model. have set ng-model

    model.test 

and sure enough seems work, did standard

    alert($scope.model.test); 

do have refer has $scope?

so when need set in controller i.e.

    $scope.model ={}; 

if want populate controller can setup like

    $scope.model = {name: 'test', age: 56}; 

but if create model ensuring had "name" , "age" set has available properties containing no value?

is normal have model created directly on scope? can not have models created separately in file.

any feedback appreciated, can see have working not 100% sure way should going

thanks in advance

$scope.model = {}; $scope.model.name = ''; // default value $scope.model.age = ''; // default value   

then can modify this:

$scope.model.name = 'test'; $scope.model.age = 56;   

or add more attributes:

$scope.model.foo = 'bar'; 

Comments