Javascript not accessible from inside Angular ui-view

前端 未结 7 1623
执念已碎
执念已碎 2021-01-18 17:56

I have a main template (index.html) with an Angular ui-view. Inside this main template I import a bunch of Javascript files. I expect these files to be available to the cont

7条回答
  •  甜味超标
    2021-01-18 18:35

    You should declare the app name using ng-app, then associate a controller with an element in the HTML. I would suggest this tutorial because you are missing few of the basics.

    You need to do something like this:

    
    
    
        
    
    
        

    app.js:

    (function () {
        var app = angular.module('myapp', []);
        app.controller("MyCtrl", function($scope){
            $scope.foo = function(){};
            this.foo2 = function(){};
        })
    })();
    

提交回复
热议问题