Angular ngController vs Controller constructed within Directive

前端 未结 4 1209
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 19:06

I\'m wondering what the use cases are for these two methods of creating a controller:

Using ngController:

myApp.controller(\'myContr         


        
4条回答
  •  被撕碎了的回忆
    2021-01-04 19:50

    The directive controller call each time when the directive is call i mean

    
    
    
    

    The directive controller call 3 time and each has own scope.

    And ngController has also same nature . But ngcontroller can also reuse in other directives / html pages .

    you can also put ngcontroller in directive (we assume that appCtrl define in any controller.js file)

    .directive('directive',function(){
        return{
             scope:{},
             template:"
    {{hello}}
    ", controller:"appCtrl" } })

提交回复
热议问题