为了账号安全,请及时绑定邮箱和手机立即绑定

这样写新版本可以正常使用

<body  ng-app="myApp">

<div  ng-controller="CommonController">

<div ng-controller="Controller1">

<p>{{greeting.text}},angular</p>

<button ng-click="test1()">test1</button>

</div>

<div  ng-controller="Controller2">

<p>{{greeting.text}},angular</p>

<button ng-click="test2()">test2</button>

</div>

<button ng-click="commonFn()">通用</button>

</div>

</body>

--------------------------------------------------------------------------

angular.module("myApp",[]).controller("CommonController",['$scope',function($scope){

$scope.commonFn=function (){

alert("这是通用功能")

}

}]).controller("Controller1",['$scope',function($scope){

$scope.greeting={

text:"hello1"

}

$scope.test1=function (){

alert("test1")

}

}]).controller("Controller2",['$scope',function($scope){

$scope.greeting={

text:"hello2"

}

$scope.test2=function (){

alert("test2")

}

}]);


正在回答

1 回答

<body ng-app="myApp">
    <div ng-controller="CommonController">
        <div ng-controller="Controller1">
            <p>{{greeting.text}},Angular</p>
            <button ng-click="test1()">test1</button>
        </div>
        <div ng-controller="Controller2">
            <p>{{greeting.text}},Angular</p>
            <button ng-click="test2()">test2</button>
        </div>
        <button ng-click="commonFn()">通用</button>
    </div>
</body>
var app = angular.module("myApp", []);
app.controller("CommonController", function($scope){
    $scope.commonFn = function(){
        alert("这是通用控制器");
    };
});

app.controller("Controller1", function($scope){
    $scope.greeting = {
        text:"Hello1"
    };
    $scope.test1 = function(){
        alert("控制器1");
    }
});

app.controller("Controller2", function($scope){
    $scope.greeting = {
        text:"Hello2"
    };
    $scope.test2 = function(){
        alert("控制器2");
    }
});


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
AngularJS实战
  • 参与学习       205465    人
  • 解答问题       1158    个

一起学习AngularJS的基础教程,通过实例学习并学会AngularJS

进入课程

这样写新版本可以正常使用

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信