2017-09-25 47 views
0
<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<body> 
 

 
<div ng-app="myApp" ng-controller="myCtrl2" ng-init="person = new Person('John','Doe')"> 
 

 
First Name: <input type="text" ng-model="person.firstName"><br> 
 
Last Name: <input type="text" ng-model="person.lastName"><br> 
 
<br> 
 

 
Full Name: {{person.sayGreeting('1')}}  
 
</div> 
 

 
<script> 
 
var app = angular.module('myApp', []); 
 

 

 

 
app.controller('myCtrl2', function ($scope) { 
 
\t 
 

 
\t \t function Person(fName,lName){ 
 
\t \t  \t this.firstName = fName; 
 
\t \t \t \t this.lastName = lName; 
 
\t \t \t \t this.sayGreeting = function(lan){ 
 
\t \t \t \t  \t if(lan=="1") return '1 : ' + this.firstName+' '+this.lastName; 
 
\t \t \t \t   
 
\t \t \t \t  \t else return '2: ' + this.firstName+' '+this.lastName; 
 
\t \t \t \t   
 
\t \t \t \t  } 
 
\t \t  } 
 
\t } 
 
    
 
    
 
}); 
 
</script> 
 

 
</body> 
 
</html>
+0

如果您發佈的代碼,而不是鏈接的一張截圖,它會更容易找到你的問題是什麼。 – zgue

+0

請幫幫我。 –

回答

1

這與一些修改代碼,我希望它可以幫助你。

<!DOCTYPE html> 
 
    <html> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
    <body> 
 
    
 
    <div ng-app="myapp" ng-controller="myCtrl2" ng-init="person = Person('John','Doe')"> 
 
    
 
    First Name: <input type="text" ng-model="person.firstName"><br> 
 
    Last Name: <input type="text" ng-model="person.lastName"><br> 
 
    <br> 
 
    
 
    Full Name: <label>{{sayGreeting('1')}}</label> 
 
    </div> 
 
    
 
    <script> 
 
    var app = angular.module('myapp', []); 
 
    
 
    
 
    
 
    app.controller('myCtrl2', function ($scope) { 
 
    \t 
 
     $scope.person={}; 
 
       
 
    \t \t $scope.Person= function(fName,lName){ 
 
    \t \t  \t $scope.person.firstName = fName; 
 
    \t \t \t \t $scope.person.lastName = lName; 
 
         return $scope.person; 
 
    
 
    \t \t \t 
 
    \t \t  } 
 
       \t $scope.sayGreeting = function(lan){ 
 
    \t \t \t \t  \t if(lan=="1") return '1 : ' + $scope.person.firstName+' '+ $scope.person.lastName; 
 
    \t \t \t \t   
 
    \t \t \t \t  \t else return '2: ' + $scope.person.firstName+' '+ $scope.person.lastName; 
 
    \t \t \t \t   
 
    \t \t \t \t  } 
 
    \t }); 
 
     
 
    
 
    </script> 
 
    
 
    </body> 
 
    </html>